package com.ga.api.controller.commission;

import com.ga.api.service.commission.CarrierReconciliationInService;
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.commission.CarrierReconciliationInResp;
import com.ga.core.vo.commission.CarrierReconciliationInSaveReq;
import com.ga.core.vo.commission.CarrierReconciliationInSearchParam;
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-recon-in")
@RequiredArgsConstructor
public class CarrierReconciliationInController {

    private final CarrierReconciliationInService service;

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

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

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

    @PostMapping("/{reconId}/reconcile")
    @RequirePermission(menu = "CARRIER_RECON_IN", perm = "UPDATE")
    @DataChangeLog(menu = "CARRIER_RECON_IN", table = "carrier_reconciliation_in")
    public ApiResponse<Void> reconcile(@PathVariable Long reconId) {
        service.reconcile(reconId);
        return ApiResponse.ok();
    }

    @PostMapping("/{reconId}/approve")
    @RequirePermission(menu = "CARRIER_RECON_IN", perm = "UPDATE")
    @DataChangeLog(menu = "CARRIER_RECON_IN", table = "carrier_reconciliation_in")
    public ApiResponse<Void> approve(@PathVariable Long reconId) {
        service.approve(reconId);
        return ApiResponse.ok();
    }
}
