package com.ga.api.controller.installment;

import com.ga.api.service.installment.InstallmentService;
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.installment.InstallmentRatioResp;
import com.ga.core.vo.installment.InstallmentRatioSaveReq;
import com.ga.core.vo.installment.InstallmentRatioSearchParam;
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/installment-ratios")
@RequiredArgsConstructor
public class InstallmentRatioController {

    private final InstallmentService installmentService;

    @GetMapping
    @RequirePermission(menu = "INSTALLMENT_RATIO", perm = "READ")
    public ApiResponse<PageResponse<InstallmentRatioResp>> list(InstallmentRatioSearchParam param) {
        return ApiResponse.ok(installmentService.listRatios(param));
    }

    @PostMapping
    @RequirePermission(menu = "INSTALLMENT_RATIO", perm = "CREATE")
    @DataChangeLog(menu = "INSTALLMENT_RATIO", table = "installment_ratio")
    public ApiResponse<Void> create(@Valid @RequestBody InstallmentRatioSaveReq req) {
        installmentService.createRatio(req);
        return ApiResponse.ok();
    }
}
