package com.ga.api.controller.commission;

import com.ga.api.service.commission.ReserveFundService;
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.AgentReserveFundResp;
import com.ga.core.vo.commission.AgentReserveFundSaveReq;
import com.ga.core.vo.commission.AgentReserveFundSearchParam;
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/reserve-funds")
@RequiredArgsConstructor
public class ReserveFundController {

    private final ReserveFundService service;

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

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

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