package com.ga.api.controller.commission;

import com.ga.api.service.commission.CommissionSimulationService;
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.CommissionSimulationResp;
import com.ga.core.vo.commission.CommissionSimulationSaveReq;
import com.ga.core.vo.commission.CommissionSimulationSearchParam;
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/commission-simulations")
@RequiredArgsConstructor
public class CommissionSimulationController {

    private final CommissionSimulationService service;

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

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

    @PostMapping("/simulate")
    @RequirePermission(menu = "COMM_SIMULATOR", perm = "CREATE")
    @DataChangeLog(menu = "COMM_SIMULATOR", table = "commission_simulation")
    public ApiResponse<CommissionSimulationResp> simulate(@Valid @RequestBody CommissionSimulationSaveReq req) {
        return ApiResponse.ok(service.simulate(req));
    }
}
