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.KnowSummariesQueryReq;
import com.seer.teach.admin.request.KnowSummariesReq;
import com.seer.teach.admin.response.KnowSummaryResp;
import com.seer.teach.admin.service.AdminKnowSummaryService;
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/know-summaries")
@RequiredArgsConstructor
@Tag(name = "管理端 - 知识点摘要管理")
@Validated
public class AdminKnowSummaryController {

    private final AdminKnowSummaryService adminKnowSummaryService;

    @PostMapping("/page-list")
    @Operation(summary = "分页查询知识点摘要列表")
    @SaCheckPermission("teacher:admin:know-summaries:list")
    public ResultBean<PageListBean<KnowSummaryResp>> pageKnowSummaries(@RequestBody @Validated KnowSummariesQueryReq req) {
        IPage<KnowSummaryResp> page = adminKnowSummaryService.pageKnowSummaries(req);
        return ResultBean.success(new PageListBean<>(page));
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据ID获取知识点摘要详情")
    @SaCheckPermission("teacher:admin:know-summaries:detail")
    public ResultBean<KnowSummaryResp> getKnowSummaryById(@Parameter(description = "知识点摘要ID") @PathVariable @NotNull(message = "知识点摘要ID不能为空") Integer id) {
        KnowSummaryResp knowSummary = adminKnowSummaryService.getKnowSummaryById(id);
        return ResultBean.success(knowSummary);
    }

    @PostMapping
    @Operation(summary = "添加知识点摘要")
    @SaCheckPermission("teacher:admin:know-summaries:save")
    public ResultBean<Boolean> addKnowSummary(@Parameter(description = "知识点摘要信息") @Valid @RequestBody KnowSummariesReq req) {
        boolean result = adminKnowSummaryService.addKnowSummary(req);
        return ResultBean.success(result);
    }

    @PutMapping("/{id}")
    @Operation(summary = "更新知识点摘要信息")
    @SaCheckPermission("teacher:admin:know-summaries:update")
    public ResultBean<Boolean> updateKnowSummary(@Parameter(description = "知识点摘要ID") @PathVariable @NotNull(message = "知识点摘要ID不能为空") Integer id,
                                                 @Parameter(description = "知识点摘要信息") @Valid @RequestBody KnowSummariesReq req) {
        boolean result = adminKnowSummaryService.updateKnowSummary(id, req);
        return ResultBean.success(result);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除知识点摘要")
    @SaCheckPermission("teacher:admin:know-summaries:delete")
    public ResultBean<Boolean> deleteKnowSummary(@Parameter(description = "知识点摘要ID") @PathVariable @NotNull(message = "知识点摘要ID不能为空") Integer id) {
        boolean result = adminKnowSummaryService.deleteKnowSummary(id);
        return ResultBean.success(result);
    }
}