package com.ym.mec.biz.service.impl;

import com.ym.mec.biz.dal.dao.OrganizationCourseDurationSettingsDao;
import com.ym.mec.biz.dal.entity.CourseSchedule.CourseScheduleType;
import com.ym.mec.biz.dal.entity.OrganizationCourseDurationSettings;
import com.ym.mec.biz.service.OrganizationCourseDurationSettingsService;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class OrganizationCourseDurationSettingsServiceImpl extends BaseServiceImpl<Integer, OrganizationCourseDurationSettings> implements OrganizationCourseDurationSettingsService {

    @Autowired
    private OrganizationCourseDurationSettingsDao organizationCourseDurationSettingsDao;

    @Override
    public BaseDAO<Integer, OrganizationCourseDurationSettings> getDAO() {
        return organizationCourseDurationSettingsDao;
    }

    @Override
    public OrganizationCourseDurationSettings queryByOrganIdAndCourseType(Integer organId, CourseScheduleType courseType) {
        return organizationCourseDurationSettingsDao.queryByOrganIdAndCourseType(organId, courseType);
    }

    @Override
    public Map<String, String> queryByOrganId(Integer organId) {
        List<OrganizationCourseDurationSettings> organizationCourseDurationSettings = organizationCourseDurationSettingsDao.queryByOrganId(organId);
        return organizationCourseDurationSettings.stream().collect(Collectors.toMap(e->e.getCourseType().getCode(), OrganizationCourseDurationSettings::getDuration));
    }

}