package com.cxy.classroll.student.controller;

import com.cxy.classroll.common.result.Result;
import com.cxy.classroll.model.entity.Lesson;
import com.cxy.classroll.model.entity.User;
import com.cxy.classroll.model.form.AuthenticationForm;
import com.cxy.classroll.model.vo.FileParam;
import com.cxy.classroll.model.vo.IdentifyAndID;
import com.cxy.classroll.student.service.CommonService;
import com.cxy.classroll.student.service.LessonInfoService;
import com.cxy.classroll.student.service.StuLessonService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

@Slf4j
@RestController
@RequestMapping("/student")
//不只有针对学生的服务接口，一些教师和学生共享的通用接口也放这
public class StudentController {
    @Autowired
    private StuLessonService studentService;

    @Autowired
    private CommonService commonService;

    @Autowired
    private LessonInfoService lessonInfoService;

    //微信小程序登录接口
    @Operation(summary = "小程序授权登录")
    @GetMapping("/common/login/{code}")
    public Result<IdentifyAndID> login(@PathVariable String code) {
        return Result.ok(commonService.login(code));
    }

    @Operation(summary = "身份校验")
    @PostMapping("/common/authentication")
    public Result<Boolean> authentication(@RequestBody AuthenticationForm authenticationForm){
        return Result.ok(commonService.authentication(authenticationForm));
    }

    @Operation(summary = "我的页面个人信息获取")
    @GetMapping("/common/userinfo/{id}")
    public Result<User> getUserInfo(@PathVariable Long id){
        return Result.ok(commonService.getUserInfo(id));
    }

    @Operation(summary = "学生课程页面课程信息列表")
    @GetMapping("/lessonlist/{id}")
    public Result<List<Lesson>> getStudentLessons(@PathVariable Long id){
        return Result.ok(studentService.getStudentLessons(id));
    }

    @Operation(summary = "学生课堂签到")
    @GetMapping("/studentsignin/{userid}/{lessonid}")
    public Result<Boolean> StudentSignInClass(@PathVariable(value = "userid") Long userid,@PathVariable(value = "lessonid")Long lessonid){
        return Result.ok(commonService.studentSignInClass(userid, lessonid));
    }

    @Operation(summary = "学生课堂签退")
    @GetMapping("/studentsignout/{userid}/{lessonid}")
    public Result<Boolean> StudentSignOutClass(@PathVariable(value = "userid") Long userid,@PathVariable(value = "lessonid")Long lessonid){
        return Result.ok(commonService.studentSignOutClass(userid, lessonid));
    }

    @Operation(summary = "监听课程状态")
    @GetMapping("/lessonstatus/{lessonid}")
    public Result<Integer> LessonStatus(@PathVariable Long lessonid){
        return Result.ok(lessonInfoService.listenLessonStatus(lessonid));
    }

    @Operation(summary = "监听课程点名状态")
    @GetMapping("/lessonroll/{lessonid}")
    public Result<Integer> LessonRoll(@PathVariable Long lessonid){
        return Result.ok(lessonInfoService.listenLessonRoll(lessonid));
    }

    @Operation(summary = "解析csv数据")
    @PostMapping(value = "/uploadcsv", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public Result<Boolean> uploadCsv(@RequestPart("multipartFile") MultipartFile multipartFile ,
                                     @RequestParam("teacher_id") Long teacher_id,
                                     @RequestParam("lesson_name") String lesson_name){
        return Result.ok(studentService.uploadCsvData(multipartFile,teacher_id,lesson_name));
    }

    @Operation(summary = "课堂随机点名")
    @GetMapping("/classroll/{lessonid}/{roll_method}")
    public Result<String> classRoll(@PathVariable(value = "lessonid") Long lessonid, @PathVariable(value = "roll_method")int roll_method){
        return Result.ok(commonService.classroll(lessonid, roll_method));
    }

    @Operation(summary = "积分排行榜")
    @GetMapping("/scorerank")
    public Result<List<User>> scoreRank(){
        return Result.ok(commonService.scoreRank());
    }

    @Operation(summary = "教师打分评价")
    @GetMapping("/comment/{lesson_id}/{student_no}/{score}")
    public Result<Boolean> comment(@PathVariable(value = "lesson_id") Long lesson_id, @PathVariable(value = "student_no") String student_no,
                                   @PathVariable(value = "score") int score){
        return Result.ok(commonService.teacherComment(lesson_id, student_no, score));
    }

    @Operation(summary = "获取课堂对应的学号信息")
    @GetMapping("/getnolist/{lesson_id}")
    public Result<List<String>> getNoList(@PathVariable(value = "lesson_id") Long lessonid){
        return Result.ok(commonService.leesonStudentNoList(lessonid));
    }
}
