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

import com.jeesharp.business.modules.finance.profitsharing.application.ProfitSharingReturnApplicationService;
import com.jeesharp.business.modules.finance.profitsharing.entity.ProfitSharingReturn;
import com.jeesharp.business.modules.finance.profitsharing.vo.ProfitSharingReturnInfoVO;
import com.jeesharp.business.modules.finance.profitsharing.vo.ProfitSharingReturnListVO;
import com.jeesharp.business.modules.finance.profitsharing.vo.ProfitSharingReturnQueryVO;
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/profitSharingReturn/v1")
@Tag(name = "分账回退")
@AllArgsConstructor
public class ProfitSharingReturnController extends BaseController {

    private final ProfitSharingReturnApplicationService profitSharingReturnApplicationService;

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

    @PostMapping("list")
    @Operation(summary = "分账回退分页列表")
    @PreAuthorize("@ss.hasPermission('manager:business:finance:profitSharingReturn:list')")
    public AjaxResult<PageRespVO<ProfitSharingReturnListVO>> list(@RequestBody ProfitSharingReturnQueryVO query) {
        return AjaxResult.okData(profitSharingReturnApplicationService.findPage(new Page<>(query), query));
    }

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