package com.seer.teach.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.seer.teach.admin.request.QuestionOptionsQueryReq;
import com.seer.teach.admin.request.QuestionOptionsReq;
import com.seer.teach.admin.response.QuestionOptionsResp;
import com.seer.teach.admin.service.AdminQuestionOptionsService;
import com.seer.teach.common.PageListBean;
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.*;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;

/**
 * <p>
 * 题目选项管理控制器
 * </p>
 *
 * @author ZS
 * @since 2025-10-24
 */
@RestController
@RequestMapping("/teacher/question-options")
@RequiredArgsConstructor
@Tag(name = "管理端 - 题目选项管理")
@Validated
public class AdminQuestionOptionsController {

    private final AdminQuestionOptionsService adminQuestionOptionsService;

    @PostMapping("/page-list")
    @Operation(summary = "分页查询题目选项列表")
    @SaCheckPermission("teacher:admin:question-options:list")
    public ResultBean<PageListBean<QuestionOptionsResp>> pageQuestionOptions(@RequestBody @Validated QuestionOptionsQueryReq req) {
        IPage<QuestionOptionsResp> page = adminQuestionOptionsService.pageQuestionOptions(req);
        return ResultBean.success(new PageListBean<>(page));
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据ID获取题目选项详情")
    @SaCheckPermission("teacher:admin:question-options:detail")
    public ResultBean<QuestionOptionsResp> getQuestionOptionById(@Parameter(description = "题目选项ID") @PathVariable @NotNull(message = "题目选项ID不能为空") Integer id) {
        QuestionOptionsResp questionOption = adminQuestionOptionsService.getQuestionOptionById(id);
        return ResultBean.success(questionOption);
    }

    @PostMapping
    @Operation(summary = "添加题目选项")
    @SaCheckPermission("teacher:admin:question-options:save")
    public ResultBean<Boolean> addQuestionOption(@Parameter(description = "题目选项信息") @Valid @RequestBody QuestionOptionsReq req) {
        boolean result = adminQuestionOptionsService.addQuestionOption(req);
        return ResultBean.success(result);
    }

    @PutMapping("/{id}")
    @Operation(summary = "更新题目选项信息")
    @SaCheckPermission("teacher:admin:question-options:update")
    public ResultBean<Boolean> updateQuestionOption(@Parameter(description = "题目选项ID") @PathVariable @NotNull(message = "题目选项ID不能为空") Integer id,
                                                 @Parameter(description = "题目选项信息") @Valid @RequestBody QuestionOptionsReq req) {
        boolean result = adminQuestionOptionsService.updateQuestionOption(id, req);
        return ResultBean.success(result);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除题目选项")
    @SaCheckPermission("teacher:admin:question-options:delete")
    public ResultBean<Boolean> deleteQuestionOption(@Parameter(description = "题目选项ID") @PathVariable @NotNull(message = "题目选项ID不能为空") Integer id) {
        boolean result = adminQuestionOptionsService.deleteQuestionOption(id);
        return ResultBean.success(result);
    }
}