package com.hzs.member.base.controller.api;

import cn.hutool.core.bean.BeanUtil;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.member.achieve.service.ICuMemberAchieveService;
import com.hzs.member.achieve.vo.CuMemberAwardsUnderVO;
import com.hzs.member.achieve.vo.CuMemberNewAddAchieveVO;
import com.hzs.member.achieve.vo.MemberAwardsNewVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * 会员首页
 */
@Slf4j
@RequestMapping("/api/member")
@RestController
public class ApiHomePageController {

    @Autowired
    private ICuMemberAchieveService cuMemberAchieveService;

    /**
     * 新增业绩
     *
     * @param dayType
     * @return AjaxResult
     */
    @GetMapping("/new-add-achieve")
    public AjaxResult newAddAchieve(Integer dayType) {
        CuMemberNewAddAchieveVO newAddAchieveVO = CuMemberNewAddAchieveVO.builder().dayType(dayType)
                .pkMember(SecurityUtils.getUserId()).pkCountry(SecurityUtils.getPkCountry()).build();
        List<CuMemberNewAddAchieveVO> cuMemberNewAddAchieveVOList = cuMemberAchieveService.selectNewAddAchieve(newAddAchieveVO);
        return AjaxResult.success(cuMemberNewAddAchieveVOList);
    }

    /**
     * 荣誉奖衔
     *
     * @return AjaxResult
     */
    @GetMapping("/index-awards")
    public AjaxResult selectAwards() {
        return AjaxResult.success(cuMemberAchieveService.selectAwardsByPkMember(SecurityUtils.getUserId(), SecurityUtils.getPkCountry()));
    }

    /**
     * 会员业绩显示 -- 昨日、月、历史业绩
     *
     * @return AjaxResult
     */
    @GetMapping("/index-member-awards")
    public AjaxResult selectMemberAwards() {
        CuMemberAwardsUnderVO resultVO = cuMemberAchieveService.indexMemberAwards(SecurityUtils.getUserId(), SecurityUtils.getPkCountry());
        return AjaxResult.success(BeanUtil.copyProperties(resultVO, MemberAwardsNewVO.class));
    }

}
