package com.zhongshu.card.server.core.controller.school;

import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.zhongshu.card.client.model.base.IDParam;
import com.zhongshu.card.client.model.school.*;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.service.school.BookInfoService;
import com.zhongshu.card.client.service.school.NoticeInfoService;
import com.zhongshu.card.client.type.OrganizationUserType;
import com.zhongshu.card.server.core.service.user.RoleServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 学校 通讯录管理
 *
 * @author TRX
 * @date 2024/6/5
 */
@RestController
@RequestMapping("/school/bookInfo")
@Tag(name = "学校-通讯录")
public class BookInfoController {

    @Autowired
    RoleServiceImpl roleService;

    @Autowired
    NoticeInfoService noticeInfoService;

    @Autowired
    BookInfoService bookInfoService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "添加-编辑教师", description = "添加-编辑教师")
    @RequestMapping(value = "addTeacher", method = {RequestMethod.POST})
    public ResultContent addTeacher(@RequestBody BookInfoAddParam param) {
        param.setUserType(OrganizationUserType.Teacher);
        return this.bookInfoService.addBookInfo(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "添加-编辑学生", description = "添加-编辑学生")
    @RequestMapping(value = "addStudent", method = {RequestMethod.POST})
    public ResultContent addStudent(@RequestBody BookInfoAddParam param) {
        param.setUserType(OrganizationUserType.Student);
        return this.bookInfoService.addBookInfo(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "删除教师", description = "删除学生")
    @RequestMapping(value = "deleteTeacher", method = {RequestMethod.POST})
    public ResultContent deleteTeacher(@RequestBody IDParam param) {
        return this.bookInfoService.deleteById(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "删除学生", description = "删除学生")
    @RequestMapping(value = "deleteStudent", method = {RequestMethod.POST})
    public ResultContent deleteStudent(@RequestBody IDParam param) {
        return this.bookInfoService.deleteById(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "教师详情", description = "教师详情")
    @RequestMapping(value = "getTeacherDetail", method = {RequestMethod.POST})
    public ResultContent<BookInfoModel> getTeacherDetail(@RequestBody IDParam param) {
        return this.bookInfoService.getByDetailById(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "学生详情", description = "学生详情")
    @RequestMapping(value = "getStudentDetail", method = {RequestMethod.POST})
    public ResultContent<BookInfoModel> getStudentDetail(@RequestBody IDParam param) {
        return this.bookInfoService.getByDetailById(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "教师列表-分页查询", description = "教师列表-分页查询")
    @RequestMapping(value = {"pageTeacher"}, method = {RequestMethod.POST})
    public ResultContent<Page<BookInfoModel>> pageTeacher(
            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
            @Parameter(required = false) BookInfoSearch param) {
        param.setUserType(OrganizationUserType.Teacher);
        return bookInfoService.page(param, pageable);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "学生列表-分页查询", description = "学生列表-分页查询")
    @RequestMapping(value = {"pageStudent"}, method = {RequestMethod.POST})
    public ResultContent<Page<BookInfoModel>> pageStudent(
            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
            @Parameter(required = false) BookInfoSearch param) {
        param.setUserType(OrganizationUserType.Student);
        return bookInfoService.page(param, pageable);
    }

}
