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

import com.jeesharp.business.modules.finance.merchantsettle.application.MerchantSettleConfigApplicationService;
import com.jeesharp.business.modules.finance.merchantsettle.dto.MerchantSettleConfigSaveDTO;
import com.jeesharp.business.modules.finance.merchantsettle.entity.MerchantSettleConfig;
import com.jeesharp.business.modules.finance.merchantsettle.vo.MerchantSettleConfigInfoVO;
import com.jeesharp.business.modules.finance.merchantsettle.vo.MerchantSettleConfigListVO;
import com.jeesharp.business.modules.finance.merchantsettle.vo.MerchantSettleConfigQueryVO;
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 jakarta.validation.Valid;
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/merchantSettle/v1")
@Tag(name = "商户结算配置")
@AllArgsConstructor
public class MerchantSettleConfigController extends BaseController {

    private final MerchantSettleConfigApplicationService merchantSettleConfigApplicationService;

    @GetMapping("info")
    @Operation(summary = "获取详情")
    @PreAuthorize("@ss.hasPermission('manager:business:finance:merchantSettle:info')")
    public AjaxResult<MerchantSettleConfigInfoVO> info(@RequestParam("id") String id) {
        return AjaxResult.okData(merchantSettleConfigApplicationService.get(id));
    }

    @PostMapping("list")
    @Operation(summary = "分页列表")
    @PreAuthorize("@ss.hasPermission('manager:business:finance:merchantSettle:list')")
    public AjaxResult<PageRespVO<MerchantSettleConfigListVO>> list(@RequestBody MerchantSettleConfigQueryVO query) {
        return AjaxResult.okData(merchantSettleConfigApplicationService.findPage(new Page<>(query), query));
    }

    @PostMapping("create")
    @Operation(summary = "新增")
    @PreAuthorize("@ss.hasPermission('manager:business:finance:merchantSettle:create')")
    public AjaxResult<Void> create(@RequestBody @Valid MerchantSettleConfigSaveDTO dto) {
        merchantSettleConfigApplicationService.create(dto);
        return AjaxResult.ok("新增成功");
    }

    @PostMapping("update")
    @Operation(summary = "更新")
    @PreAuthorize("@ss.hasPermission('manager:business:finance:merchantSettle:update')")
    public AjaxResult<Void> update(@RequestBody @Valid MerchantSettleConfigSaveDTO dto) {
        merchantSettleConfigApplicationService.update(dto);
        return AjaxResult.ok("更新成功");
    }

    @GetMapping("delete")
    @Operation(summary = "删除")
    @PreAuthorize("@ss.hasPermission('manager:business:finance:merchantSettle:delete')")
    public AjaxResult<Void> delete(@RequestParam("ids") String ids) {
        merchantSettleConfigApplicationService.delete(ids);
        return AjaxResult.ok("删除成功");
    }
}
