package top.awinx.stu01.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.awinx.stu01.common.Result;
import top.awinx.stu01.dto.TeacherAddDTO;
import top.awinx.stu01.dto.TeacherUpdateDTO;
import top.awinx.stu01.entity.Teacher;
import top.awinx.stu01.service.TeacherService;

/**
 * 教师CRUD控制器
 */
@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Resource
    private TeacherService teacherService;

    /**
     * 添加教师
     * POST /api/teacher/add
     */
    @PostMapping("/add")
    public Result<Teacher> addTeacher(@RequestBody TeacherAddDTO addDTO) {
        Teacher teacher = teacherService.addTeacher(addDTO);
        return Result.success("添加教师成功", teacher);
    }

    /**
     * 更新教师
     * PUT /api/teacher/update
     */
    @PutMapping("/update")
    public Result<Boolean> updateTeacher(@RequestBody TeacherUpdateDTO updateDTO) {
        boolean success = teacherService.updateTeacher(updateDTO);
        return Result.success("更新教师成功", success);
    }

    /**
     * 删除教师
     * DELETE /api/teacher/delete/{id}
     */
    @DeleteMapping("/delete/{id}")
    public Result<Boolean> deleteTeacher(@PathVariable Long id) {
        boolean success = teacherService.deleteTeacher(id);
        return Result.success("删除教师成功", success);
    }
}
