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

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.org.RegionModel;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.server.core.service.org.RegionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("region")
@Slf4j
@Tag(name = "地区管理")
public class RegionController {

    @Autowired
    RegionService regionService;

//    @ResourceAuth(value = "regionManager", type = AuthType.Platform, remark = "区域管理_区域列表_1_Menu")
//    @ResourceAuth(value = "regionManager", type = AuthType.Project, remark = "区域管理_区域列表_1_Menu")
//    @ResourceAuth(value = "regionManager", type = AuthType.School, remark = "区域管理_区域列表_1_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 = "")
    @Operation(summary = "获取地区数据")
    @RequestMapping(value = "getRegionManager", method = RequestMethod.POST)
    @ResourceAuth(value = AuthConstant.User, type = AuthType.User)
    public ResultContent<List<RegionModel>> getRegionManager(
            @RequestBody @Validated RegionModel regionModel) {
        return regionService.getRegion(regionModel);
    }


    @Operation(summary = "获取地区数据")
    @RequestMapping(value = "getRegion", method = RequestMethod.POST)
    @ResourceAuth(value = AuthConstant.User, type = AuthType.User)
    public ResultContent<List<RegionModel>> getRegion(@RequestBody @Validated RegionModel regionModel) {
        return regionService.getRegion(regionModel);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "地区树形结构-通用", description = "得到机构部门树")
    @RequestMapping(value = "getAllTree", method = {RequestMethod.GET})
    public ResultContent getAllTree() {
        return this.regionService.getAllTree();
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "地区列表-异步构件树用", description = "得到机构部门树")
    @RequestMapping(value = "getList", method = {RequestMethod.GET})
    public ResultContent getList(
            @Parameter(name = "parentId", description = "上级id,为空查询最上层", required = false)
            @RequestParam(name = "parentId")
            String parentId) {
        return this.regionService.getListByParentCode(parentId);
    }

}
