package com.ruoyi.web.controller.front;

import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Lists;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.dz.service.IDzControlService;
import com.ruoyi.dz.service.IDzSubjectService;
import com.ruoyi.learn.domain.LearnTest;
import com.ruoyi.learn.service.ILearnTestService;
import com.ruoyi.web.service.LearnTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/front/teacher")
@Api(tags = "前台-学习-老师")
public class FrontTeacherController extends BaseController {
    private final IDzControlService dzControlService;
    private final IDzSubjectService dzSubjectService;
    private final ILearnTestService learnTestService;
    private final LearnTeacherService learnTeacherService;

    public FrontTeacherController(IDzControlService dzControlService, IDzSubjectService dzSubjectService, ILearnTestService learnTestService, LearnTeacherService learnTeacherService) {
        this.dzControlService = dzControlService;
        this.dzSubjectService = dzSubjectService;
        this.learnTestService = learnTestService;
        this.learnTeacherService = learnTeacherService;
    }

    @ApiOperation("10 查询班级列表")
    @GetMapping("classes")
    public AjaxResult getClasses()
    {
        return AjaxResult.success(learnTeacherService.getClasses(getUserId()));
    }

    @ApiOperation("10 查询批次列表")
    @GetMapping("batchs")
    public AjaxResult getBatchs()
    {
        List<LearnTest> list = learnTestService.selectLearnTestList(new LearnTest());
        return AjaxResult.success(list);
    }

    @ApiOperation("记录-模拟卷")
    @GetMapping("record/simulated")
    public AjaxResult getRecordSimulated()
    {
        JSONObject result = new JSONObject();
        result.put("total", 140);
        result.put("done", 85);
        result.put("undone", 3);
        result.put("unsent", 3);
        JSONObject data = JSONObject.of("name", "2501", "data", "242");
        List<JSONObject> list = Lists.newArrayList(data);
        result.put("list", list);
        return AjaxResult.success(result);
    }

    @ApiOperation("记录-模拟卷班级")
    @GetMapping("record/simulated/{classId}")
    public AjaxResult getRecordSimulated(@ApiParam("班级id") @PathVariable("classId") Integer classId)
    {
        JSONObject data = JSONObject.of("seq", "1", "name", "XM", "total", "658", "study", 20, "rate", 39);
        List<JSONObject> list = Lists.newArrayList(data);
        return AjaxResult.success(list);
    }

    @ApiOperation("记录-测试卷")
    @GetMapping("record/test")
    public AjaxResult getRecordTest(Integer batch)
    {
        JSONObject result = new JSONObject();
        result.put("total", 140);
        result.put("done", 85);
        result.put("undone", 3);
        result.put("unsent", 3);
        JSONObject data = JSONObject.of("name", "2501", "data", "242");
        List<JSONObject> list = Lists.newArrayList(data);
        result.put("list", list);
        return AjaxResult.success(result);
    }

    @ApiOperation("记录-测试卷班级")
    @GetMapping("record/test/{classId}")
    public AjaxResult getRecordTestDetail(@ApiParam("班级id") @PathVariable("classId") Integer classId)
    {
        JSONObject data = JSONObject.of("seq", "1", "name", "XM", "total", "658", "study", 20, "rate", 39);
        List<JSONObject> list = Lists.newArrayList(data);
        return AjaxResult.success(list);
    }

    @ApiOperation("记录-计划刷题 有班级显示学生")
    @GetMapping("record/planStudy")
    public AjaxResult getRecordStudy()
    {
        JSONObject data = JSONObject.of("seq", "1", "name", "XM", "total", "658", "study", 20, "rate", 39);
        List<JSONObject> list = Lists.newArrayList(data);
        return AjaxResult.success(list);
    }

    @ApiOperation("记录-计划刷题明细")
    @GetMapping("record/planStudy/{id}")
    public AjaxResult getRecordPlanStudyDetail(Integer year, Integer monthSeq, Integer weekSeq, @ApiParam("记录sid") @PathVariable("recordId") Integer recordId)
    {
        JSONObject result = new JSONObject();
        result.put("total", 140);
        result.put("rate", 85);
        result.put("studyDays", 3);
        JSONObject data = JSONObject.of("date", "2025.09.03", "study", "90", "rate", "80", "pass", true);
        List<JSONObject> list = Lists.newArrayList(data);
        result.put("list", list);
        return AjaxResult.success(result);
    }

    @ApiOperation("知识点")
    @GetMapping("record/knowledge")
    public AjaxResult getRecordKnowledge(@ApiParam("班级id") Integer classId)
    {
        JSONObject result = new JSONObject();
        result.put("rate", 48);
        JSONObject data = JSONObject.of("seq", "1", "name", "XM", "total", "658", "rate", 39);
        List<JSONObject> list = Lists.newArrayList(data);
        result.put("list", list);
        return AjaxResult.success(result);
    }

    @ApiOperation("知识点")
    @GetMapping("record/knowledge/{recordId}")
    public TableDataInfo getRecordKnowledgeDetail(@ApiParam("记录sid") @PathVariable("recordId") Integer recordId)
    {
        JSONObject data = JSONObject.of("name", "", "directed", true, "rate", 82, "total", 1470);
        List<JSONObject> list = Lists.newArrayList(data);
        return getDataTable(list);
    }

    @ApiOperation("视频记录")
    @GetMapping("record/video")
    public AjaxResult getRecordVideo(@ApiParam("班级id") Integer classId)
    {
        JSONObject result = new JSONObject();
        JSONObject data = JSONObject.of("seq", "1", "name", "XM", "total", "658", "study", 20);
        List<JSONObject> list = Lists.newArrayList(data);
        result.put("list", list);
        return AjaxResult.success(result);
    }

    @ApiOperation("视频记录")
    @GetMapping("record/video/{recordId}")
    public AjaxResult getRecordVideoDetail(@ApiParam("记录sid") @PathVariable("recordId") Integer recordId)
    {
        JSONObject result = new JSONObject();
        result.put("total", 98);
        result.put("study", 759);
        JSONObject data = JSONObject.of("name", "充分条件", "date", "2025.09.11", "study", "02:46");
        List<JSONObject> list = Lists.newArrayList(data);
        result.put("list", list);
        return AjaxResult.success(result);
    }
}
