package com.ga.api.controller.settle;

import com.ga.api.service.settle.CarrierReconciliationOutService;
import com.ga.common.annotation.DataChangeLog;
import com.ga.common.annotation.RequirePermission;
import com.ga.common.model.ApiResponse;
import com.ga.common.model.PageResponse;
import com.ga.core.vo.settle.CarrierReconciliationOutResp;
import com.ga.core.vo.settle.CarrierReconciliationOutSaveReq;
import com.ga.core.vo.settle.CarrierReconciliationOutSearchParam;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "보험사 회신 관리")
@RestController
@RequestMapping("/api/carrier-reconciliation")
@RequiredArgsConstructor
public class CarrierReconciliationOutController {

    private final CarrierReconciliationOutService service;

    @GetMapping
    @RequirePermission(menu = "RECON_OUT", perm = "READ")
    public ApiResponse<PageResponse<CarrierReconciliationOutResp>> list(@ModelAttribute CarrierReconciliationOutSearchParam param) {
        return ApiResponse.ok(service.list(param));
    }

    @GetMapping("/{reconOutId}")
    @RequirePermission(menu = "RECON_OUT", perm = "READ")
    public ApiResponse<CarrierReconciliationOutResp> detail(@PathVariable Long reconOutId) {
        return ApiResponse.ok(service.detail(reconOutId));
    }

    @PostMapping
    @RequirePermission(menu = "RECON_OUT", perm = "CREATE")
    @DataChangeLog(menu = "RECON_OUT", table = "carrier_reconciliation_out")
    public ApiResponse<Long> create(@Valid @RequestBody CarrierReconciliationOutSaveReq req) {
        return ApiResponse.ok(service.create(req));
    }

    @PostMapping("/{reconOutId}/retry")
    @RequirePermission(menu = "RECON_OUT", perm = "UPDATE")
    @DataChangeLog(menu = "RECON_OUT", table = "carrier_reconciliation_out")
    public ApiResponse<Void> retry(@PathVariable Long reconOutId) {
        service.retry(reconOutId);
        return ApiResponse.ok();
    }
}
