package co.yixiang.yshop.module.member.controller.app.userlevel;

import co.yixiang.yshop.framework.common.pojo.CommonResult;
import co.yixiang.yshop.framework.security.core.annotations.PreAuthenticated;
import co.yixiang.yshop.framework.security.core.util.SecurityFrameworkUtils;
import co.yixiang.yshop.module.member.controller.admin.userlevelconfig.vo.UserLevelConfigExportReqVO;
import co.yixiang.yshop.module.member.controller.admin.userlevelconfig.vo.UserLevelConfigRespVO;
import co.yixiang.yshop.module.member.controller.admin.userlevelequity.vo.UserLevelEquityRespVO;
import co.yixiang.yshop.module.member.controller.admin.userlevelgrowthvalueconfig.vo.UserLevelGrowthValueConfigExportReqVO;
import co.yixiang.yshop.module.member.controller.admin.userlevelgrowthvalueconfig.vo.UserLevelGrowthValueConfigRespVO;
import co.yixiang.yshop.module.member.controller.app.userlevel.vo.SettleLevelInfoVO;
import co.yixiang.yshop.module.member.controller.app.userlevel.vo.UserLevelInfoVO;
import co.yixiang.yshop.module.member.convert.userlevelconfig.UserLevelConfigConvert;
import co.yixiang.yshop.module.member.convert.userlevelequity.UserLevelEquityConvert;
import co.yixiang.yshop.module.member.convert.userlevelgrowthvalueconfig.UserLevelGrowthValueConfigConvert;
import co.yixiang.yshop.module.member.dal.dataobject.userlevelconfig.UserLevelConfigDO;
import co.yixiang.yshop.module.member.dal.dataobject.userlevelequity.UserLevelEquityDO;
import co.yixiang.yshop.module.member.dal.dataobject.userlevelgrowthvalueconfig.UserLevelGrowthValueConfigDO;
import co.yixiang.yshop.module.member.service.userlevelconfig.UserLevelConfigService;
import co.yixiang.yshop.module.member.service.userlevelequityref.UserLevelEquityRefService;
import co.yixiang.yshop.module.member.service.userlevelgrowthvalueconfig.UserLevelGrowthValueConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author pepis
 * @apiNote
 **/
@RestController
@RequestMapping("/member/user-level")
@Tag(name = "app-用户等级")
public class AppUserLevelController {
    @Resource
    private UserLevelGrowthValueConfigService growthValueConfigService;
    @Resource
    private UserLevelConfigService userLevelConfigService;
    @Resource
    private UserLevelEquityRefService userLevelEquityRefService;

    @GetMapping("growthValueConfig")
    @Operation(summary = "成长任务")
    @PreAuthenticated
    public CommonResult<List<UserLevelGrowthValueConfigRespVO>> growthValueConfig() {
        List<UserLevelGrowthValueConfigDO> list = growthValueConfigService.getUserLevelGrowthValueConfigList(new UserLevelGrowthValueConfigExportReqVO());
        return CommonResult.success(UserLevelGrowthValueConfigConvert.INSTANCE.convertList(list));
    }

    @GetMapping("levelConfig")
    @Operation(summary = "等级列表")
    @PreAuthenticated
    public CommonResult<List<UserLevelConfigRespVO>> levelConfig() {
        UserLevelConfigExportReqVO reqVO = new UserLevelConfigExportReqVO();
        reqVO.setStatus(Boolean.TRUE);
        List<UserLevelConfigDO> list = userLevelConfigService.getUserLevelConfigList(reqVO);
        return CommonResult.success(UserLevelConfigConvert.INSTANCE.convertList(list));
    }

    @GetMapping("levelInfo")
    @Operation(summary = "等级信息")
    @PreAuthenticated
    public CommonResult<UserLevelInfoVO> levelInfo() {
        UserLevelInfoVO vo = userLevelConfigService.levelInfo(SecurityFrameworkUtils.getLoginUserId());
        return CommonResult.success(vo);
    }

    @GetMapping("equity")
    @Operation(summary = "会员等级对应权益")
    @PreAuthenticated
    public CommonResult<List<UserLevelEquityRespVO>> equity(Long levelId) {
        List<UserLevelEquityDO> list = userLevelEquityRefService.getUserLevelEquityList(levelId);
        return CommonResult.success(UserLevelEquityConvert.INSTANCE.convertList(list));
    }

    @GetMapping("settleLevelInfo")
    @Operation(summary = "结算时等级信息")
    @PreAuthenticated
    public CommonResult<SettleLevelInfoVO> settleLevelInfo() {
        SettleLevelInfoVO vo = userLevelConfigService.settleLevelInfo(SecurityFrameworkUtils.getLoginUserId());
        return CommonResult.success(vo);
    }


}
