package cn.nianxx.thhotel.workflows.reservation.control;

import cn.nianxx.thhotel.workflows.reservation.common.request.ReservationDemoDataSeedRequest;
import cn.nianxx.thhotel.workflows.reservation.common.result.ReservationDemoDataSeedResult;
import cn.nianxx.thhotel.workflows.reservation.service.ReservationDemoDataService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Reservation 演示数据 Controller。该入口只在 dev/test 显式开启时注册，用于前端联调造数。
 */
@RestController
@RequestMapping("/api/system/reservation/demo-data")
@ConditionalOnProperty(prefix = "reservation.demo-data", name = "enabled", havingValue = "true")
public class ReservationDemoDataController {

    private final ReservationDemoDataService demoDataService;

    /**
     * 注入演示数据服务，Controller 不直接访问持久化层。
     */
    public ReservationDemoDataController(ReservationDemoDataService demoDataService) {
        this.demoDataService = demoDataService;
    }

    /**
     * 生成一批前端演示数据；调用方必须携带受控访问口令。
     */
    @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<ReservationDemoDataSeedResult> seed(
            @RequestHeader(name = "X-TH-Hotel-Demo-Data-Key", required = false) String accessKey,
            @RequestBody(required = false) ReservationDemoDataSeedRequest request) {
        return ResponseEntity.status(HttpStatus.CREATED).body(demoDataService.seed(request, accessKey));
    }
}
