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.TeachMethodsReq;
import com.seer.teach.admin.response.TeachMethodsResp;
import com.seer.teach.admin.service.AdminTeachMethodsService;
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;
import java.util.List;

/**
 * <p>
 * 管理端 - 教学方法管理
 * </p>
 *
 * @author Lingma
 * @since 2025-12-04
 */
@RestController
@RequestMapping("/teacher/teach-method")
@RequiredArgsConstructor
@Tag(name = "管理端 - 教学方法管理")
@Validated
public class AdminTeachMethodsController {

    private final AdminTeachMethodsService adminTeachMethodsService;

    @GetMapping("/paged")
    @Operation(summary = "分页查询教学方法列表")
    @SaCheckPermission("teacher:admin:teach-methods:paged")
    public ResultBean<PageListBean<TeachMethodsResp>> pageTeachMethods(@Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer pageNo,
                                                                       @Parameter(description = "每页数量") @RequestParam(defaultValue = "10") Integer pageSize) {
        IPage<TeachMethodsResp> page = adminTeachMethodsService.pageTeachMethods(pageNo, pageSize);
        return ResultBean.success(new PageListBean<>(page));
    }

    @GetMapping("/list")
    @Operation(summary = "查询教学方法列表")
    @SaCheckPermission("teacher:admin:teach-methods:list")
    public ResultBean<List<TeachMethodsResp>> getTeachMethodList(@Parameter(description = "教学方法名称") @RequestParam(required = false) String methodName) {
        List<TeachMethodsResp> data = adminTeachMethodsService.getTeachMethodList(methodName);
        return ResultBean.success(data);
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据ID获取教学方法详情")
    @SaCheckPermission("teacher:admin:teach-methods:detail")
    public ResultBean<TeachMethodsResp> getTeachMethodById(@Parameter(description = "教学方法ID") @PathVariable @NotNull(message = "教学方法ID不能为空") Integer id) {
        TeachMethodsResp teachMethod = adminTeachMethodsService.getTeachMethodById(id);
        return ResultBean.success(teachMethod);
    }

    @PostMapping
    @Operation(summary = "添加教学方法")
    @SaCheckPermission("teacher:admin:teach-methods:save")
    public ResultBean<Boolean> addTeachMethod(@Parameter(description = "教学方法信息") @Valid @RequestBody TeachMethodsReq req) {
        boolean result = adminTeachMethodsService.addTeachMethod(req);
        return ResultBean.success(result);
    }

    @PutMapping("/{id}")
    @Operation(summary = "更新教学方法信息")
    @SaCheckPermission("teacher:admin:teach-methods:update")
    public ResultBean<Boolean> updateTeachMethod(@Parameter(description = "教学方法ID") @PathVariable @NotNull(message = "教学方法ID不能为空") Integer id,
                                                @Parameter(description = "教学方法信息") @Valid @RequestBody TeachMethodsReq req) {
        boolean result = adminTeachMethodsService.updateTeachMethod(id, req);
        return ResultBean.success(result);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除教学方法")
    @SaCheckPermission("teacher:admin:teach-methods:delete")
    public ResultBean<Boolean> deleteTeachMethod(@Parameter(description = "教学方法ID") @PathVariable @NotNull(message = "教学方法ID不能为空") Integer id) {
        boolean result = adminTeachMethodsService.deleteTeachMethod(id);
        return ResultBean.success(result);
    }
}