package com.cxy.classroll.student.service.impl;

import com.cxy.classroll.common.execption.CxyException;
import com.cxy.classroll.common.result.Result;
import com.cxy.classroll.common.result.ResultCodeEnum;
import com.cxy.classroll.model.entity.Lesson;
import com.cxy.classroll.model.vo.FileParam;
import com.cxy.classroll.student.client.StudentFeignClient;
import com.cxy.classroll.student.service.StudentWebService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class StudentWebServiceImpl implements StudentWebService {

    @Autowired
    private StudentFeignClient studentFeignClient;
    @Override
    public List<Lesson> getStudentLessons(Long id) {
        Result<List<Lesson>> result = studentFeignClient.getStudentLessons(id);
        Integer code = result.getCode();
        if (code!=200){
            throw new CxyException(ResultCodeEnum.DATA_ERROR);
        }

        List<Lesson> data = result.getData();
        if (data == null){
            throw new CxyException(ResultCodeEnum.DATA_ERROR);
        }

        return data;
    }

    @Override
    public Boolean uploadCsvData(MultipartFile multipartFile,Long teacher_id, String lesson_name) {
        FileParam fileParam = new FileParam();
        fileParam.setMultipartFile(multipartFile);
        fileParam.setLesson_name(lesson_name);
        fileParam.setTeacher_id(teacher_id);
        Result<Boolean> result = studentFeignClient.uploadCsv(multipartFile, teacher_id, lesson_name);
        if (result.getCode()!=200){
            throw new CxyException(ResultCodeEnum.DATA_ERROR);
        }
        return result.getData();
    }
}
