package com.ga.api.controller.commission;

import com.ga.api.service.commission.OverrideLedgerService;
import com.ga.common.annotation.RequirePermission;
import com.ga.common.model.ApiResponse;
import com.ga.common.model.PageResponse;
import com.ga.core.vo.commission.*;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "오버라이드 원장")
@RestController
@RequestMapping("/api/override-ledgers")
@RequiredArgsConstructor
public class OverrideLedgerController {

    private final OverrideLedgerService service;

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

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

    @GetMapping("/summary")
    @RequirePermission(menu = "OVERRIDE_LEDGER", perm = "READ")
    public ApiResponse<List<OverrideSummaryResp>> summaryList(@ModelAttribute OverrideSummarySearchParam param) {
        return ApiResponse.ok(service.summaryList(param));
    }

    @GetMapping("/summary/by-agent")
    @RequirePermission(menu = "OVERRIDE_LEDGER", perm = "READ")
    public ApiResponse<OverrideSummaryResp> summaryByAgent(@RequestParam Long toAgentId,
                                                           @RequestParam String settleMonth) {
        return ApiResponse.ok(service.summaryByAgentAndMonth(toAgentId, settleMonth));
    }
}
