package com.ga.api.controller.withdraw;

import com.ga.api.service.withdraw.WithdrawRequestService;
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.withdraw.WithdrawRequestResp;
import com.ga.core.vo.withdraw.WithdrawRequestSaveReq;
import com.ga.core.vo.withdraw.WithdrawRequestSearchParam;
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/withdraw-requests")
@RequiredArgsConstructor
public class WithdrawRequestController {

    private final WithdrawRequestService service;

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

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

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

    @PostMapping("/{requestId}/cancel")
    @RequirePermission(menu = "WITHDRAW", perm = "UPDATE")
    @DataChangeLog(menu = "WITHDRAW", table = "withdraw_request")
    public ApiResponse<Void> cancel(@PathVariable Long requestId) {
        service.cancel(requestId);
        return ApiResponse.ok();
    }
}
