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.PayAppBo;
import org.dromara.pay.domain.vo.PayAppVo;
import org.dromara.pay.service.PayAppService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * 支付应用
 *
 * @author pengles
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pay/app")
public class PayAppController extends BaseController {

    private final PayAppService payAppService;

    /**
     * 查询支付应用列表
     */
    @SaCheckPermission("pay:app:list")
    @GetMapping("/list")
    public TableDataInfo<PayAppVo> list(PayAppBo bo, PageQuery pageQuery) {
        return payAppService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取支付应用详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("pay:app:query")
    @GetMapping("/{id}")
    public R<PayAppVo> getInfo(@PathVariable Long id) {
        return R.ok(payAppService.queryById(id));
    }

    /**
     * 新增支付应用
     */
    @SaCheckPermission("pay:app:add")
    @Log(title = "支付应用", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody PayAppBo bo) {
        return toAjax(payAppService.insertByBo(bo));
    }

    /**
     * 修改支付应用
     */
    @SaCheckPermission("pay:app:edit")
    @Log(title = "支付应用", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody PayAppBo bo) {
        return toAjax(payAppService.updateByBo(bo));
    }

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