package com.ruoyi.web.modules.pay.controller;

import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.modules.pay.dto.ShopWechatPayAuditRejectDTO;
import com.ruoyi.web.modules.pay.dto.ShopWechatPayPlatformQuery;
import com.ruoyi.web.modules.pay.service.IShopWechatPayService;

/**
 * 平台端 · 微信支付入驻审核
 */
@RestController
@RequestMapping("/agri/shop/wechat-pay")
public class PlatformShopWechatPayController extends BaseController
{
    @Autowired
    private IShopWechatPayService shopWechatPayService;

    @PreAuthorize("@ss.hasPermi('agri:shop:wechatPay:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopWechatPayPlatformQuery query)
    {
        startPage();
        return getDataTable(shopWechatPayService.selectPlatformList(query));
    }

    @PreAuthorize("@ss.hasPermi('agri:shop:wechatPay:list')")
    @GetMapping("/pendingCount")
    public AjaxResult pendingCount()
    {
        Map<String, Object> data = new HashMap<>();
        data.put("pendingCount", shopWechatPayService.countPlatformPending());
        return success(data);
    }

    @PreAuthorize("@ss.hasPermi('agri:shop:wechatPay:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shopWechatPayService.selectPlatformDetail(id));
    }

    @PreAuthorize("@ss.hasPermi('agri:shop:wechatPay:audit')")
    @Log(title = "微信支付入驻审核通过", businessType = BusinessType.UPDATE)
    @PutMapping("/approve/{shopId}")
    public AjaxResult approve(@PathVariable("shopId") Long shopId)
    {
        shopWechatPayService.auditApprove(shopId, getUsername());
        return success();
    }

    @PreAuthorize("@ss.hasPermi('agri:shop:wechatPay:audit')")
    @Log(title = "微信支付入驻审核驳回", businessType = BusinessType.UPDATE)
    @PutMapping("/reject")
    public AjaxResult reject(@RequestBody ShopWechatPayAuditRejectDTO dto)
    {
        shopWechatPayService.auditReject(dto, getUsername());
        return success();
    }
}
