package com.njcn.user.controller.app;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.user.pojo.vo.app.RoleReferralCodeVO;
import com.njcn.user.service.IReferralCodeService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2023/6/25 16:13
 */
@Validated
@Slf4j
@RestController
@RequestMapping("/referralCode")
@Api(tags = "推荐码管理")
@AllArgsConstructor
public class ReferralCodeController extends BaseController {

    private final IReferralCodeService referralCodeService;


    /**
     * 查看角色推荐码
     * 1.用完就生成新的推荐码
     * 2.规定时间内失效，重新生成推荐码
     */
    @PostMapping("findReferralCode")
    @OperateInfo
    @ApiOperation(value = "查看角色推荐码", notes = "生成角色推荐码")
    public HttpResult<List<RoleReferralCodeVO>> findReferralCode() {
        String methodDescribe = getMethodDescribe("findReferralCode");
        List<RoleReferralCodeVO> list = referralCodeService.findReferralCode();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    /**
     * 刷新角色推荐码
     * 1.重新生成推荐码
     */
    @PostMapping("refreshReferralCode")
    @OperateInfo
    @ApiOperation(value = "刷新角色推荐码", notes = "刷新角色推荐码")
    @ApiIgnore
    public HttpResult<List<RoleReferralCodeVO>> refreshReferralCode() {
        String methodDescribe = getMethodDescribe("refreshReferralCode");
        List<RoleReferralCodeVO> list = referralCodeService.refreshReferralCode();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

}
