package com.seer.teach.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.seer.teach.admin.response.VersionMappingResp;
import com.seer.teach.admin.response.VersionResp;
import com.seer.teach.admin.service.AdminVersionsService;
import com.seer.teach.common.ResultBean;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import jakarta.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 管理端 - 版本管理控制器
 * </p>
 *
 * @author Lingma
 * @since 2025-10-29
 */
@RestController
@RequestMapping("/teacher/version")
@RequiredArgsConstructor
@Tag(name = "管理端 - 版本管理")
@Validated
public class AdminVersionsController {

    private final AdminVersionsService adminVersionsService;

    /**
     * 根据科目ID获取版本列表
     *
     * @return 版本列表响应结果
     */
    @GetMapping("/list")
    @Operation(summary = "根据科目ID获取版本列表")
    @SaCheckPermission("teacher:admin:version:mapping:list")
    public ResultBean<List<VersionMappingResp>> listVersionMappings() {
        List<VersionMappingResp> list = adminVersionsService.listVersionMappings();
        return ResultBean.success(list);
    }

    /**
     * 根据学科ID获取版本列表
     *
     * @param subjectId 学科ID
     * @return 版本列表响应结果
     */
    @GetMapping("/list-by-subject")
    @Operation(summary = "根据学科ID获取版本列表")
    @SaCheckPermission("teacher:admin:version:list-by-subject")
    public ResultBean<List<VersionResp>> listBySubjectId(
            @Parameter(description = "学科ID") @RequestParam @NotNull(message = "学科ID不能为空") Integer subjectId) {
        List<VersionResp> list = adminVersionsService.listBySubjectId(subjectId);
        return ResultBean.success(list);
    }


    /**
     * 根据学科ID和年级ID获取版本列表
     *
     * @param subjectId 学科ID
     * @return 版本列表响应结果
     */
    @GetMapping("/{subjectId}/{gradeId}/list")
    @Operation(summary = "根据学科ID获取版本列表")
    @SaCheckPermission("teacher:admin:version:list-by-subject")
    public ResultBean<List<VersionResp>> listBySubjectIdAndGradeId(@PathVariable("subjectId") Integer subjectId,@PathVariable("gradeId") Integer gradeId) {
        List<VersionResp> list = adminVersionsService.listBySubjectIdAndGradeId(subjectId,gradeId);
        return ResultBean.success(list);
    }
}