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.base.OidModel;
import com.zhongshu.card.client.model.school.CollegeParam;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.service.school.CollegeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
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;

@RestController
@RequestMapping("/school/college")
@Tag(name = "学校-院级管理")
public class CollegeController {

    @Autowired
    private CollegeService collegeService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "添加-编辑院级", description = "添加-编辑院级")
    @RequestMapping(value = "addCollege", method = {RequestMethod.POST})
    public ResultContent addCollege(@RequestBody CollegeParam param) {
        return this.collegeService.addCollege(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "得到机构院级树", description = "得到机构院级树")
    @RequestMapping(value = "getCollegeTree", method = {RequestMethod.POST})
    public ResultContent getCollegeTree(@RequestBody OidModel param) {
        return this.collegeService.getCollegeTree(param.getOid());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "删除院级", description = "删除院级")
    @RequestMapping(value = "deleteCollege", method = {RequestMethod.POST})
    public ResultContent deleteCollege(@RequestBody IDParam param) {
        return this.collegeService.deleteCollege(param.getId());
    }

}
