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.CommonWebService;
import com.cxy.classroll.student.service.StudentWebService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.annotation.MultipartConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Slf4j
@Tag(name = "学生及通用API接口管理")
@RestController
@RequestMapping("/student")
public class StudentWebController {

    @Autowired
    private CommonWebService commonWebService;

    @Autowired
    private StudentWebService studentWebService;


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

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

    @Operation(summary = "我的主页用户信息获取")
    @GetMapping("/common/getUserInfo/{id}")
    public Result<User> getUserInfo(@PathVariable Long id){
        return Result.ok(commonWebService.getUserInfo(id));
    }

    @Operation(summary = "学生课程列表信息获取")
    @GetMapping("/lessonlist/{id}")
    public Result<List<Lesson>> getStudentLessons(@PathVariable Long id){
        return Result.ok(studentWebService.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(commonWebService.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(commonWebService.studentSignOutClass(userid, lessonid));
    }

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

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

    @Operation(summary = "上传学生csv名单文件")
    @PostMapping("/uploadcsv")
    public Result<Boolean> uploadCsv(@RequestParam("multipartFile") MultipartFile multipartFile ,
                                     @RequestParam("teacher_id") Long teacher_id,
                                     @RequestParam("lesson_name") String lesson_name){
        System.out.println(teacher_id);
        System.out.println(lesson_name);
        return Result.ok(studentWebService.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(commonWebService.classRoll(lessonid, roll_method));
    }

    @Operation(summary = "积分排行榜")
    @GetMapping("/scorerank")
    public Result<List<User>> scoreRank(){
        return Result.ok(commonWebService.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(commonWebService.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(commonWebService.leesonStudentNoList(lessonid));
    }
}
