package org.dromara.payment.operator.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.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.operator.domain.vo.BusOperatorAgreementVo;
import org.dromara.payment.operator.domain.bo.BusOperatorAgreementBo;
import org.dromara.payment.operator.service.IBusOperatorAgreementService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 运营商协议
 * 前端访问路由地址为:/payment/operatorAgreement
 *
 * @author LionLi
 * @date 2024-03-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/operatorAgreement")
public class BusOperatorAgreementController extends BaseController {

    private final IBusOperatorAgreementService busOperatorAgreementService;

    /**
     * 查询运营商协议列表
     */
    @SaCheckPermission("payment:operatorAgreement:list")
    @GetMapping("/list")
    public TableDataInfo<BusOperatorAgreementVo> list(BusOperatorAgreementBo bo, PageQuery pageQuery) {
        return busOperatorAgreementService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出运营商协议列表
     */
    @SaCheckPermission("payment:operatorAgreement:export")
    @Log(title = "运营商协议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BusOperatorAgreementBo bo, HttpServletResponse response) {
        List<BusOperatorAgreementVo> list = busOperatorAgreementService.queryList(bo);
        ExcelUtil.exportExcel(list, "运营商协议", BusOperatorAgreementVo.class, response);
    }

    /**
     * 获取运营商协议详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("payment:operatorAgreement:query")
    @GetMapping("/{id}")
    public R<BusOperatorAgreementVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(busOperatorAgreementService.queryById(id));
    }

    /**
     * 新增运营商协议
     */
    @SaCheckPermission("payment:operatorAgreement:add")
    @Log(title = "运营商协议", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BusOperatorAgreementBo bo) {
        return toAjax(busOperatorAgreementService.insertByBo(bo));
    }

    /**
     * 修改运营商协议
     */
    @SaCheckPermission("payment:operatorAgreement:edit")
    @Log(title = "运营商协议", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BusOperatorAgreementBo bo) {
        return toAjax(busOperatorAgreementService.updateByBo(bo));
    }

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