package com.education.business.service.education;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.education.business.mapper.education.HomeworkInfoMapper;
import com.education.business.service.BaseService;
import com.education.common.model.PageInfo;
import com.education.model.dto.GoalInfoDto;
import com.education.model.dto.HomeworkInfoDto;
import com.education.model.entity.GoalInfo;
import com.education.model.entity.HomeworkInfo;
import com.education.model.request.PageParam;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author zhangj
 * @version 1.0
 * @create_at
 */
@Service
public class HomeworkInfoService extends BaseService<HomeworkInfoMapper, HomeworkInfo> {

    public PageInfo<HomeworkInfoDto> selectPageList(PageParam pageParam, HomeworkInfo homeworkInfo) {
        Page<HomeworkInfoDto> page = new Page<>(pageParam.getPageNumber(), pageParam.getPageSize());
        return selectPage(baseMapper.selectPageList(page, homeworkInfo));
    }

    @Override
    public boolean saveOrUpdate(HomeworkInfo homeworkInfo) {
        return super.saveOrUpdate(homeworkInfo);
    }

    public List<GoalInfoDto> getGoals(Integer id) {
        //todo implement getGoals
        List<GoalInfoDto>  goalInfo =  baseMapper.getGoals(id);
        return goalInfo;
    }

    public void assign(Integer id) {
        //todo implement assign
        HomeworkInfo homeworkInfo =  super.getById(id);
        homeworkInfo.setPublishFlag(1);  //1为发布
        saveOrUpdate(homeworkInfo);
    }
}