package com.schoolinout.web.controller.system;

import com.schoolinout.common.core.controller.BaseController;
import com.schoolinout.common.core.domain.AjaxResult;
import com.schoolinout.system.domain.dto.AddTeacherClassRelationDto;
import com.schoolinout.system.domain.dto.BindClassTeacherMain;
import com.schoolinout.system.domain.dto.RelationListDto;
import com.schoolinout.system.service.ITeacherClassRelationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author sakura
 * @date 2024/1/4 09:9:53 Thu
 */
@Tag(name = "教师和班级关系表")
@RestController
@RequestMapping("/system/relation")
public class TeacherClassRelationController extends BaseController {

    private final ITeacherClassRelationService teacherClassRelationService;

    public TeacherClassRelationController(ITeacherClassRelationService teacherClassRelationService) {
        this.teacherClassRelationService = teacherClassRelationService;
    }


    @Operation(summary = "绑定/解绑-班级班主任关系", description = "teacherMain参数发送Y 就是绑定；发送N 就是解绑")
    @PostMapping("/bind/class/teacherMain")
    public AjaxResult bindClassTeacherMain(@Validated @RequestBody BindClassTeacherMain form) {
        return success(teacherClassRelationService.bindClassTeacherMain(form));
    }

    @Operation(description = "获取关系列表")
    @GetMapping("/info/list")
    public AjaxResult getTeacherClassInfo(RelationListDto form) {
        return success(teacherClassRelationService.queryTeacherBindClassList(form));
    }

    /**
     * 以老师为主，绑定多个班级的关系
     */
    @Operation(summary = "以老师为主，绑定多个班级的关系")
    @PostMapping("/bind/teacher")
    public AjaxResult bindTeacherClass(@Validated @RequestBody AddTeacherClassRelationDto form) {
        return toAjax(teacherClassRelationService.bindTeacherClass(form));
    }

    /**
     * 搜索 教师绑定的班级
     *
     * @param teacherId
     * @return
     */
    @GetMapping("/search/{teacherId}")
    public AjaxResult searchTeacherBindClass(@PathVariable Long teacherId) {
        return success(teacherClassRelationService.listTeacherBindClass(teacherId));
    }
}
