package com.ga.api.controller.tax;

import com.ga.api.service.tax.VatReportService;
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.tax.VatReportResp;
import com.ga.core.vo.tax.VatReportSaveReq;
import com.ga.core.vo.tax.VatReportSearchParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "부가세 분기신고")
@RestController
@RequestMapping("/api/vat-reports")
@RequiredArgsConstructor
public class VatReportController {

    private final VatReportService service;

    @GetMapping
    @Operation(summary = "부가세 분기신고 목록 조회")
    @RequirePermission(menu = "VAT_REPORT", perm = "READ")
    public ApiResponse<PageResponse<VatReportResp>> list(
            @ModelAttribute VatReportSearchParam param) {
        return ApiResponse.ok(service.list(param));
    }

    @GetMapping("/{id}")
    @Operation(summary = "부가세 분기신고 상세 조회")
    @RequirePermission(menu = "VAT_REPORT", perm = "READ")
    public ApiResponse<VatReportResp> detail(@PathVariable Long id) {
        return ApiResponse.ok(service.detail(id));
    }

    @PostMapping("/regenerate")
    @Operation(summary = "분기 부가세 재집계")
    @RequirePermission(menu = "VAT_REPORT", perm = "EXECUTE")
    @DataChangeLog(menu = "VAT_REPORT", table = "vat_report")
    public ApiResponse<Integer> regenerate(@Valid @RequestBody VatReportSaveReq req) {
        return ApiResponse.ok(service.regenerate(req));
    }

    @PutMapping("/complete")
    @Operation(summary = "부가세 분기신고 제출 완료 처리")
    @RequirePermission(menu = "VAT_REPORT", perm = "EXECUTE")
    @DataChangeLog(menu = "VAT_REPORT", table = "vat_report")
    public ApiResponse<Void> complete(@RequestBody Map<String, List<Long>> body) {
        service.complete(body.get("ids"));
        return ApiResponse.ok();
    }
}
