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

import com.github.microservice.auth.client.constant.AuthConstant;
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.IDsParam;
import com.zhongshu.card.client.model.base.OidModel;
import com.zhongshu.card.client.model.school.AreaParam;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.service.school.AreaService;
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.util.Assert;
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;

import javax.validation.Valid;

/**
 * 项目的区域管理
 */
@RestController
@RequestMapping("/school/area")
@Tag(name = "项目-区域管理")
public class AreaController {

    @Autowired
    AreaService areaService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "添加-编辑区域-通用", description = "添加-编辑区域")
    @RequestMapping(value = "addArea", method = {RequestMethod.POST})
    public ResultContent addArea(@RequestBody @Valid AreaParam param) {
        Assert.hasText(param.getOid(), "oid不能为空");
        return this.areaService.addArea(param);
    }

    //    @ResourceAuth(value = "projectAreaManager", type = AuthType.Platform, remark = "区域管理_区域列表_160_Menu")
    @ResourceAuth(value = "projectAreaManager", type = AuthType.Project, remark = "区域管理_区域列表_160_Menu")
    @ResourceAuth(value = "projectAreaManager", type = AuthType.School, remark = "区域管理_区域列表_160_Menu")
    @ResourceAuth(value = "projectAreaManager", type = AuthType.BusinessMain, remark = "区域管理_区域列表_160_Menu")
    @ResourceAuth(value = "projectAreaManager", type = AuthType.CommonOrg, remark = "区域管理_区域列表_160_Menu")
    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
    @ResourceAuth(value = AuthConstant.Admin, type = AuthType.Project, remark = "")
    @ResourceAuth(value = AuthConstant.Admin, type = AuthType.School, remark = "")
    @ResourceAuth(value = AuthConstant.Admin, type = AuthType.BusinessMain, remark = "")
    @ResourceAuth(value = AuthConstant.Admin, type = AuthType.CommonOrg, remark = "")
    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "得到机构区域树-通用", description = "得到机构区域树")
    @RequestMapping(value = "getManagerAreaTree", method = {RequestMethod.POST})
    public ResultContent getManagerAreaTree(@RequestBody @Valid OidModel param) {
        return this.areaService.getAreaTree(param.getOid());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "得到机构区域树-通用", description = "得到机构区域树")
    @RequestMapping(value = "getAreaTree", method = {RequestMethod.POST})
    public ResultContent getAreaTree(@RequestBody @Valid OidModel param) {
        return this.areaService.getAreaTree(param.getOid());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "删除区域-通用", description = "删除区域")
    @RequestMapping(value = "deleteArea", method = {RequestMethod.POST})
    public ResultContent deleteArea(@RequestBody IDParam param) {
        Assert.hasText(param.getId(), "id不能为空");
        return this.areaService.deleteArea(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "删除区域(多个)-通用", description = "删除区域(多个)")
    @RequestMapping(value = "deleteAreas", method = {RequestMethod.POST})
    public ResultContent deleteAreas(@RequestBody IDsParam param) {
        return this.areaService.deleteAreas(param);
    }

}
