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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
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 : 商户管理
 */
@Api(tags = "商户号管理")
@RestController
@RequestMapping("/pay/merchant")
public class PayMerchantController {

    @Autowired
    private IPayMerchantService payMerchantService;

    @ApiOperation(value = "商户添加或者更新")
    @PostMapping(value = "/add/or/update")
    @PreAuthorize(permissionKey = "manage:payMerchant:addOrUpdate")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> list(@Validated @RequestBody PayMerchantAddUpdateParam param) {
        return ResultVO.ok(payMerchantService.addOrUpdate(param));
    }

    @ApiOperation(value = "商户列表查询")
    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:payMerchant:list")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = PayMerchantListVO.class)})
    public ResultVO<IPage<PayMerchantListVO>> list(@Validated @RequestBody PayMerchantListParam param) {
        return ResultVO.ok(payMerchantService.pageList(param));
    }

    @ApiOperation(value = "商户删除")
    @DeleteMapping(value = "/delete")
    @PreAuthorize(permissionKey = "manage:payMerchant:delete")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> deleteById(@RequestParam Long id) {
        return ResultVO.ok(payMerchantService.deleteById(id));
    }

    @ApiOperation(value = "商户状态变更")
    @PatchMapping(value = "/status/update")
    @PreAuthorize(permissionKey = "manage:payMerchant:statusUpdate")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> statusUpdate(@RequestParam Long id, @RequestParam Integer status) {
        return ResultVO.ok(payMerchantService.statusUpdate(id, status));
    }

    @ApiOperation(value = "商户密钥变更")
    @PatchMapping(value = "/secret/key/update")
    @PreAuthorize(permissionKey = "manage:payMerchant:secretKeyUpdate")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> secretKeyUpdate(@RequestParam Long id, @RequestParam String secretKey) {
        return ResultVO.ok(payMerchantService.secretKeyUpdate(id, secretKey));
    }
}
