package cn.reghao.tnb.content.app.data.controller;

import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.common.auth.AuthUser;
import cn.reghao.tnb.content.app.data.service.ChartService;
import cn.reghao.tnb.content.app.exam.model.chart.LineChartData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author reghao
 * @date 2025-08-19 21:44:54
 */
@Tag(name = "图表数据接口")
@RestController
@RequestMapping("/api/content/chart")
public class ChartController {
    private final ChartService chartService;

    public ChartController(ChartService chartService) {
        this.chartService = chartService;
    }

    @Operation(summary = "获取用户考试结果的统计数据", description = "N")
    @GetMapping(value = "/exam/count", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getExamCount() {
        List<String> list = new ArrayList<>();
        list.add("试卷1,试卷2,试卷3,试卷4,试卷4,试卷6,试卷7");
        list.add("8,4,1,8,0,0,0");
        return WebResult.success(list);
    }

    @Operation(summary = "获取用户的考试通过率", description = "N")
    @GetMapping(value = "/exam/rate", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getExamPassRate() {
        List<String> list = new ArrayList<>();
        list.add("试卷1,试卷2,试卷3,试卷4,试卷4,试卷6,试卷7");
        list.add("0.5,1.0,1.0,1.0,0.0,0.0,0.0");
        return WebResult.success(list);
    }

    @Operation(summary = "获取折线图数据", description = "N")
    @GetMapping(value = "/exam/linechart", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getLineChart() {
        LineChartData lineChartData = chartService.getLineChartData();
        return WebResult.success(lineChartData);
    }

    @AuthUser
    @Operation(summary = "用户最近一周观看视频时长统计", description = "N")
    @GetMapping(value = "/video/watch", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getWatchLineChart() {
        List<String> list = chartService.getWatchLineChart();
        return WebResult.success(list);
    }

    @AuthUser
    @Operation(summary = "用户最近一周观看视频分区统计", description = "N")
    @GetMapping(value = "/video/region", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getRegionPieChart() {
        List<String> list = chartService.getRegionPieChart();
        return WebResult.success(list);
    }
}
