package com.jeesharp.business.modules.finance.profitsharing.controller;

import com.jeesharp.business.modules.finance.profitsharing.application.ProfitSharingApplicationService;
import com.jeesharp.business.modules.finance.profitsharing.vo.ProfitSharingOrderInfoVO;
import com.jeesharp.business.modules.finance.profitsharing.vo.ProfitSharingOrderListVO;
import com.jeesharp.business.modules.finance.profitsharing.vo.ProfitSharingOrderQueryVO;
import com.jeesharp.framework.pojo.AjaxResult;
import com.jeesharp.framework.pojo.Page;
import com.jeesharp.framework.pojo.query.PageRespVO;
import com.jeesharp.framework.web.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 微信分账管理 REST 接口，提供失败补单重试等运营能力。
 *
 * @author jeesharp
 * @since 2026-06-11
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/finance/profitSharing/v1")
@Tag(name = "微信分账")
@AllArgsConstructor
public class ProfitSharingController extends BaseController {

    private final ProfitSharingApplicationService profitSharingApplicationService;

    @GetMapping("info")
    @Operation(summary = "获取分账单详情")
    @PreAuthorize("@ss.hasPermission('manager:business:finance:profitSharing:info')")
    public AjaxResult<ProfitSharingOrderInfoVO> info(@RequestParam("id") String id) {
        return AjaxResult.okData(profitSharingApplicationService.get(id));
    }

    @PostMapping("list")
    @Operation(summary = "分账单分页列表")
    @PreAuthorize("@ss.hasPermission('manager:business:finance:profitSharing:list')")
    public AjaxResult<PageRespVO<ProfitSharingOrderListVO>> list(@RequestBody ProfitSharingOrderQueryVO query) {
        return AjaxResult.okData(profitSharingApplicationService.findPage(new Page<>(query), query));
    }

    @PostMapping("retry")
    @Operation(summary = "手动重试分账")
    @PreAuthorize("@ss.hasPermission('manager:business:finance:profitSharing:retry')")
    public AjaxResult<Void> retry(@RequestParam("id") String id) {
        profitSharingApplicationService.retry(id);
        return AjaxResult.ok("重试已提交");
    }
}
