package org.dromara.pay.controller.admin;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.pay.domain.bo.PayChannelBo;
import org.dromara.pay.domain.vo.PayChannelVo;
import org.dromara.pay.service.PayChannelService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 支付渠道
 *
 * @author pengles
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pay/channel")
public class PayChannelController extends BaseController {

    private final PayChannelService payChannelService;

    /**
     * 查询支付渠道列表
     */
    @SaCheckPermission("pay:channel:list")
    @GetMapping("/list")
    public TableDataInfo<PayChannelVo> list(PayChannelBo bo, PageQuery pageQuery) {
        return payChannelService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取支付渠道详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("pay:channel:query")
    @GetMapping("/{id}")
    public R<PayChannelVo> getInfo(@PathVariable Long id) {
        return R.ok(payChannelService.queryById(id));
    }

    /**
     * 新增支付渠道
     */
    @SaCheckPermission("pay:channel:add")
    @Log(title = "支付渠道", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody PayChannelBo bo) {
        return toAjax(payChannelService.insertByBo(bo));
    }

    /**
     * 修改支付渠道
     */
    @SaCheckPermission("pay:channel:edit")
    @Log(title = "支付渠道", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody PayChannelBo bo) {
        return toAjax(payChannelService.updateByBo(bo));
    }

    /**
     * 删除支付渠道
     *
     * @param ids 主键串
     */
    @SaCheckPermission("pay:channel:remove")
    @Log(title = "支付渠道", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        return toAjax(payChannelService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
