/**
 * @filename:CustomerAssignController 2024-06-03
 * @project trade-admin V1.0 Copyright(c) 2024 wanglang Co. Ltd. All right reserved.
 */
package com.trade.admin.enterprise.customer.controller.api;

import javax.annotation.Resource;

import com.trade.admin.enterprise.customer.domain.CustomerReferralCode;
import com.trade.admin.enterprise.customer.service.CustomerReferralCodeService;
import com.trade.admin.enterprise.customer.service.CustomerAssignService;
import com.trade.common.core.domain.ResponseResult;
import org.springframework.web.bind.annotation.*;

import com.trade.admin.system.controller.BaseController;

import io.swagger.annotations.Api;

/**
 * <p>
 * 说明： 客户移交分配内部接口层
 * </P>
 * 
 * @version: V1.0
 * @author: wanglang
 * @time 2024-06-03
 */
@Api(tags = "客户分配内部接口", value = "客户分配内部接口")
@RestController
@RequestMapping("/api/customerAssign")
public class CustomerAssignApiController extends BaseController {

    @Resource
    private CustomerAssignService customerAssignService;
    @Resource
    private CustomerReferralCodeService customerReferralCodeService;


    /**
     * 保存客户分配信息
     * 
     * @param customerUserId C端客户id
     * @param referralCode 推荐码
     * @param identifierNo C端账号唯一标识
     * @return 是否成功
     */
    @PostMapping("/save")
    public ResponseResult<Boolean> addCustomerAssign(Long customerUserId, String referralCode, String identifierNo) {
        return success(customerAssignService.addCustomerAssign(customerUserId, referralCode, identifierNo));
    }

    /**
     * 验证推荐码的有效性
     *
     * @param referralCode 推荐码值
     * @return ResponseResult<Boolean>
     */
    @GetMapping(value = "/checkReferralCode")
    public ResponseResult<Boolean> checkCode(String referralCode) {
        return success(customerReferralCodeService.checkCode(referralCode));
    }

    /**
     * 根据推荐链接中后缀的唯一标识，查询推荐码
     * 
     * @param urlSuffix 推荐链接中后缀
     * @return 推荐码
     */
    @GetMapping(value = "/getReferralCode")
    public ResponseResult<String> getCode(String urlSuffix) {
        CustomerReferralCode referralCode = customerReferralCodeService.getByReferralUrlSuffix(urlSuffix);
        String code = "";
        if (null != referralCode) {
            code = referralCode.getReferralCode();
        }
        return success(code);
    }
}
