package com.zanxiang.game.module.manage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zanxiang.erp.security.annotation.PreAuthorize;
import com.zanxiang.game.module.manage.pojo.params.PayMerchantAddUpdateParam;
import com.zanxiang.game.module.manage.pojo.params.PayMerchantListParam;
import com.zanxiang.game.module.manage.pojo.vo.PayMerchantListVO;
import com.zanxiang.game.module.manage.service.IPayMerchantService;
import com.zanxiang.module.util.pojo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author : lingfeng
 * @time : 2022-11-25
 * @description : 商户管理
 */
@RestController
@RequestMapping("/pay/merchant")
public class PayMerchantController {

    @Autowired
    private IPayMerchantService payMerchantService;

    @PostMapping(value = "/add/or/update")
    @PreAuthorize(permissionKey = "manage:payMerchant:addOrUpdate")
    public ResultVO<Boolean> list(@Validated @RequestBody PayMerchantAddUpdateParam param) {
        return ResultVO.ok(payMerchantService.addOrUpdate(param));
    }

    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:payMerchant:list")
    public ResultVO<IPage<PayMerchantListVO>> list(@Validated @RequestBody PayMerchantListParam param) {
        return ResultVO.ok(payMerchantService.pageList(param));
    }

    @DeleteMapping(value = "/delete")
    @PreAuthorize(permissionKey = "manage:payMerchant:delete")
    public ResultVO<Boolean> deleteById(@RequestParam Long id) {
        return ResultVO.ok(payMerchantService.deleteById(id));
    }

    @PatchMapping(value = "/status/update")
    @PreAuthorize(permissionKey = "manage:payMerchant:statusUpdate")
    public ResultVO<Boolean> statusUpdate(@RequestParam Long id, @RequestParam Integer status) {
        return ResultVO.ok(payMerchantService.statusUpdate(id, status));
    }

    @PatchMapping(value = "/secret/key/update")
    @PreAuthorize(permissionKey = "manage:payMerchant:secretKeyUpdate")
    public ResultVO<Boolean> secretKeyUpdate(@RequestParam Long id, @RequestParam String secretKey) {
        return ResultVO.ok(payMerchantService.secretKeyUpdate(id, secretKey));
    }
}
