package com.zioinfo.kintex.ticket.cancel;

import com.zioinfo.kintex.common.ApiResponse;
import com.zioinfo.kintex.ticket.cancel.TicketCancelDtos.CancelRequest;
import com.zioinfo.kintex.ticket.cancel.TicketCancelDtos.RefundQuoteDto;
import jakarta.validation.Valid;
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.RestController;

/**
 * F-B2 티켓 취소·환불 공개 API — 전 경로 {@code /api/public/**} permitAll.
 * <p>본인확인(예매번호+연락처). 예상 환불액은 서버 권위 산출.
 */
@RestController
@RequestMapping("/api/public/tickets")
public class TicketCancelController {

    private final TicketCancelService service;

    public TicketCancelController(TicketCancelService service) {
        this.service = service;
    }

    /** POST /refund-quote — 취소 전 예상 환불 산정(조회만). */
    @PostMapping("/refund-quote")
    public ApiResponse<RefundQuoteDto> quote(@Valid @RequestBody CancelRequest req) {
        return ApiResponse.ok(service.quote(req.orderNo(), req.contact()));
    }

    /** POST /cancel — 실제 취소 처리(상태 전이·재고 원복·환불 스냅샷). */
    @PostMapping("/cancel")
    public ApiResponse<RefundQuoteDto> cancel(@Valid @RequestBody CancelRequest req) {
        return ApiResponse.ok(service.cancel(req.orderNo(), req.contact()));
    }
}
