package org.dromara.payment.sys.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.payment.sys.domain.vo.SysSydSignContentVo;
import org.dromara.payment.sys.service.ISysSydSignContentService;
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.payment.sys.domain.bo.SysSydSignContentBo;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 服务商协议内容
 * 前端访问路由地址为:/payment/sydSignContent
 *
 * @author LionLi
 * @date 2024-03-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/sydSignContent")
public class SysSydSignContentController extends BaseController {

    private final ISysSydSignContentService sysSydSignContentService;

    /**
     * 查询服务商协议内容列表
     */
    @SaCheckPermission("payment:sydSignContent:list")
    @GetMapping("/list")
    public TableDataInfo<SysSydSignContentVo> list(SysSydSignContentBo bo, PageQuery pageQuery) {
        return sysSydSignContentService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出服务商协议内容列表
     */
    @SaCheckPermission("payment:sydSignContent:export")
    @Log(title = "服务商协议内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysSydSignContentBo bo, HttpServletResponse response) {
        List<SysSydSignContentVo> list = sysSydSignContentService.queryList(bo);
        ExcelUtil.exportExcel(list, "服务商协议内容", SysSydSignContentVo.class, response);
    }

    /**
     * 获取服务商协议内容详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("payment:sydSignContent:query")
    @GetMapping("/{id}")
    public R<SysSydSignContentVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(sysSydSignContentService.queryById(id));
    }

    /**
     * 新增服务商协议内容
     */
    @SaCheckPermission("payment:sydSignContent:add")
    @Log(title = "服务商协议内容", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysSydSignContentBo bo) {
        return toAjax(sysSydSignContentService.insertByBo(bo));
    }

    /**
     * 修改服务商协议内容
     */
    @SaCheckPermission("payment:sydSignContent:edit")
    @Log(title = "服务商协议内容", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysSydSignContentBo bo) {
        return toAjax(sysSydSignContentService.updateByBo(bo));
    }

    /**
     * 删除服务商协议内容
     *
     * @param ids 主键串
     */
    @SaCheckPermission("payment:sydSignContent:remove")
    @Log(title = "服务商协议内容", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(sysSydSignContentService.deleteWithValidByIds(List.of(ids), true));
    }
}
