package org.dromara.web.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.web.domain.bo.ChargeSetBo;
import org.dromara.web.domain.vo.ChargeSetVo;
import org.dromara.web.service.IChargeSetService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 收费设置
 *
 * @author Lion Li
 * @date 2025-08-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/parameter/chargeSet")
public class ChargeSetController extends BaseController {

    private final IChargeSetService chargeSetService;

    /**
     * 查询收费设置列表
     */
    @SaCheckPermission("parameter:chargeSet:list")
    @GetMapping("/list")
    public TableDataInfo<ChargeSetVo> list(ChargeSetBo bo, PageQuery pageQuery) {
        return chargeSetService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出收费设置列表
     */
    @SaCheckPermission("parameter:chargeSet:export")
    @Log(title = "收费设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ChargeSetBo bo, HttpServletResponse response) {
        List<ChargeSetVo> list = chargeSetService.queryList(bo);
        ExcelUtil.exportExcel(list, "收费设置", ChargeSetVo.class, response);
    }

    /**
     * 获取收费设置详细信息
     *
     * @param chargeId 主键
     */
    @SaCheckPermission("parameter:chargeSet:query")
    @GetMapping("/{chargeId}")
    public R<ChargeSetVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long chargeId) {
        return R.ok(chargeSetService.queryById(chargeId));
    }

    /**
     * 新增收费设置
     */
    @SaCheckPermission("parameter:chargeSet:add")
    @Log(title = "收费设置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ChargeSetBo bo) {
        return toAjax(chargeSetService.insertByBo(bo));
    }

    /**
     * 修改收费设置
     */
    @SaCheckPermission("parameter:chargeSet:edit")
    @Log(title = "收费设置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ChargeSetBo bo) {
        return toAjax(chargeSetService.updateByBo(bo));
    }

    /**
     * 删除收费设置
     *
     * @param chargeIds 主键串
     */
    @SaCheckPermission("parameter:chargeSet:remove")
    @Log(title = "收费设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{chargeIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] chargeIds) {
        return toAjax(chargeSetService.deleteWithValidByIds(List.of(chargeIds), true));
    }
}
