package com.ruoyi.school.member.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.core.api.APIResponse;
import com.ruoyi.school.course.domain.ScCourseType;
import com.ruoyi.school.course.domain.req.course.ReqBusinessOrderCourseDetail;
import com.ruoyi.school.course.domain.resp.course.RespBusinessChooseCourseInfo;
import com.ruoyi.school.course.service.IScCourseTypeService;
import com.ruoyi.school.member.domain.ScMemberCardCourses;
import com.ruoyi.school.member.domain.ScMemberCardTypes;
import com.ruoyi.school.member.domain.req.ReqAddMemberChargeItem;
import com.ruoyi.school.member.domain.resp.MemberCardVO;
import com.ruoyi.school.member.mapper.ScMemberCardTypesMapper;
import com.ruoyi.school.member.service.IScMemberCardService;
import com.ruoyi.school.member.service.ScMemberCardChargeService;
import com.ruoyi.school.member.service.ScMemberCardCourseService;
import com.ruoyi.school.member.service.ScMemberCardTypesService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 会员卡类型信息 服务实现类
 * </p>
 *
 */
@Service
public class ScMemberCardTypesServiceImpl extends ServiceImpl<ScMemberCardTypesMapper, ScMemberCardTypes> implements ScMemberCardTypesService {

    @Autowired
    private IScMemberCardService memberCardService;
    @Autowired
    private IScCourseTypeService courseTypeService;
    @Autowired
    private ScMemberCardChargeService cardChargeService;

    @Autowired
    private ScMemberCardCourseService cardCoursesService;
    @Autowired
    private ISysUserService userService;

    @Override
    public void memberTypeDetail(ScMemberCardTypes l){
        if (ObjectUtil.isNotEmpty(l.getCourseTypes())||l.getCourseTypes().length>0){
            List<Long> courseTypeIds = Arrays.asList(l.getCourseTypes());
            List<ScCourseType> courseTypeList=courseTypeService.listByIds(courseTypeIds);
            String typesName= courseTypeList.stream().map(ScCourseType::getCourseType)
                    .collect(Collectors.joining(","));
            l.setCourseTypesName(typesName);
        }
        //付费模式 default  customize自定义
        if (l.getChargeType().equals("customize")){
            List<ReqAddMemberChargeItem> list=cardChargeService.getByMemberId(l.getCardTypeId());
            l.setFeeModeHourList(list);
        }
        //限制教练
        if (l.getRestrictedTeacher().equals("2") ){
            List<SysUser> users= userService.selectUserByIds(l.getTeacherList());
            String userNames= users.stream().map(SysUser::getNickName).collect(Collectors.joining(","));
            l.setTeachersName(userNames);
        }
        //限制课程
        if (l.getRestrictedCourses().equals("2")){
            //课程类别名称 课程名称
            List<ScMemberCardCourses> cardCoursesList=cardCoursesService.getByCardId(l.getCardTypeId());
            l.setCourses(cardCoursesList);
        }

    }


}
