package com.ruoyi.web.modules.news.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.modules.news.domain.AgriculturalCourseListVo;
import com.ruoyi.web.modules.news.domain.AgriculturalCourseQuery;
import com.ruoyi.web.modules.news.domain.AgriculturalCourseRow;
import com.ruoyi.web.modules.news.mapper.AgriculturalCourseMapper;
import com.ruoyi.web.modules.news.service.IAgriculturalCourseService;
import com.ruoyi.web.modules.news.support.AgriculturalCourseQuerySupport;

@Service
public class AgriculturalCourseServiceImpl implements IAgriculturalCourseService
{
    @Autowired
    private AgriculturalCourseMapper agriculturalCourseMapper;

    @Override
    public List<AgriculturalCourseListVo> selectAgriculturalCourseList(AgriculturalCourseQuery query)
    {
        AgriculturalCourseQuery effective = AgriculturalCourseQuerySupport.normalize(query);
        List<AgriculturalCourseRow> rows = agriculturalCourseMapper.selectAgriculturalCourseList(effective);
        if (rows == null || rows.isEmpty())
        {
            return Collections.emptyList();
        }
        List<AgriculturalCourseListVo> result = new ArrayList<>(rows.size());
        for (AgriculturalCourseRow row : rows)
        {
            result.add(toListVo(row));
        }
        return result;
    }

    private static AgriculturalCourseListVo toListVo(AgriculturalCourseRow row)
    {
        AgriculturalCourseListVo vo = new AgriculturalCourseListVo();
        vo.setId(row.getId());
        vo.setTitle(row.getTitle());
        vo.setIntroduction(row.getIntroduction());
        vo.setType(row.getType());
        vo.setCoverFileUrl(row.getCoverFileUrl());
        vo.setContentFileUrl(row.getContentFileUrl());
        vo.setPublishTime(row.getPublishTime());
        vo.setActualEnrolledCount(row.getActualEnrolledCount());
        vo.setPlannedHeadCount(row.getPlannedHeadCount());
        vo.setRegistrationStartTime(row.getRegistrationStartTime());
        vo.setRegistrationEndTime(row.getRegistrationEndTime());
        vo.setTrainingTime(row.getTrainingTime());
        vo.setExpectedOutcome(row.getExpectedOutcome());
        return vo;
    }
}
