package com.ycwl.basic.controller.mobile;

import com.ycwl.basic.constant.BaseContextHandler;
import com.ycwl.basic.pricing.dto.req.VoucherClaimReq;
import com.ycwl.basic.pricing.dto.req.VoucherPrintReq;
import com.ycwl.basic.pricing.dto.resp.VoucherCodeResp;
import com.ycwl.basic.pricing.dto.resp.VoucherPrintResp;
import com.ycwl.basic.pricing.service.VoucherCodeService;
import com.ycwl.basic.pricing.service.VoucherPrintService;
import com.ycwl.basic.utils.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
@RequestMapping("/api/mobile/voucher/v1")
public class AppVoucherController {
    
    @Autowired
    private VoucherPrintService voucherPrintService;
    @Autowired
    private VoucherCodeService voucherCodeService;

    /**
     * 打印小票
     * @param request 打印请求
     * @return 打印结果
     */
    @PostMapping("/print")
    public ApiResponse<VoucherPrintResp> printVoucherTicket(@RequestBody VoucherPrintReq request) {
        log.info("收到打印小票请求: faceId={}, brokerId={}, scenicId={}", 
                 request.getFaceId(), request.getBrokerId(), request.getScenicId());
        
        VoucherPrintResp response = voucherPrintService.printVoucherTicket(request);
        
        log.info("打印小票完成: code={}, voucherCode={}, status={}", 
                 response.getCode(), response.getVoucherCode(), response.getPrintStatus());
        
        return ApiResponse.success(response);
    }

    @GetMapping("/printed")
    public ApiResponse<VoucherPrintResp> queryPrintedVoucher(
            @RequestParam Long faceId
    ) {
        return ApiResponse.success(voucherPrintService.queryPrintedVoucher(faceId));
    }

    @PostMapping("/claim")
    public ApiResponse<VoucherCodeResp> claimVoucher(@RequestBody VoucherClaimReq req) {
        VoucherCodeResp result = voucherCodeService.claimVoucher(req);
        return ApiResponse.success(result);
    }

}
