package com.czg.controller.admin;

import com.czg.annotation.SaAdminCheckPermission;
import com.czg.annotation.SaAdminCheckRole;
import com.czg.constant.PayChannelCst;
import com.czg.exception.CzgException;
import com.czg.order.dto.ShopMerchantDTO;
import com.czg.order.entity.ShopDirectMerchant;
import com.czg.order.service.ShopMerchantService;
import com.czg.resp.CzgResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 商户信息管理
 *
 * @author Administrator
 */
@RestController
@RequestMapping("/admin/shopMerchant")
public class ShopMerchantController {
    @Resource
    private ShopMerchantService shopMerchantService;

    /**
     * 商户支付信息获取
     * 权限标识: shopMerchant:detail
     *
     * @param shopId 店铺id
     * @return 支付信息
     */
    @SaAdminCheckRole("管理员")
    @SaAdminCheckPermission(parentName = "支付参数信息", value = "shopMerchant:detail", name = "商户支付信息获取")
    @GetMapping
    public CzgResult<ShopMerchantDTO> detail(@RequestParam Long shopId) {
        return CzgResult.success(shopMerchantService.detail(shopId));
    }

    /**
     * 商户支付信息修改
     * 权限标识: shopMerchant:edit
     *
     * @return 是否成功
     */
    @SaAdminCheckRole("管理员")
    @SaAdminCheckPermission(parentName = "支付参数信息", value = "shopMerchant:edit", name = "商户支付信息修改")
    @PutMapping
    public CzgResult<Boolean> edit(@RequestBody ShopMerchantDTO shopMerchant) {
        if (shopMerchant != null && shopMerchant.getChannel() != null && shopMerchant.getChannel().equals(PayChannelCst.NATIVE)) {
            throw new CzgException("原生支付渠道暂未开通");
        }
        return CzgResult.success(shopMerchantService.editEntry(shopMerchant, true));
    }

    /**
     * 获取当前店铺的主店进件信息
     */
    @SaAdminCheckRole("管理员")
    @GetMapping("getMainMerchant")
    public CzgResult<ShopDirectMerchant> getMainMerchant(Long shopId) {
        return CzgResult.success(shopMerchantService.getMainMerchant(shopId));
    }
}
