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.github.microservice.net.ResultContent;
import com.zhongshu.card.client.model.base.IDParam;
import com.zhongshu.card.client.model.school.DictInfoParam;
import com.zhongshu.card.client.model.school.DictInfoSearch;
import com.zhongshu.card.client.service.school.DictInfoService;
import com.zhongshu.card.client.type.DictInfoType;
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;

import java.util.List;

/**
 * 区域类型 管理
 *
 * @author TRX
 * @date 2024/6/5
 */
@RestController
@RequestMapping("areaTypeManager")
@Tag(name = "区域类型管理")
public class AreaTypeManagerController {

    @Autowired
    DictInfoService dictInfoService;

    //    @ResourceAuth(value = "projectAreaTypeManager", type = AuthType.Platform, remark = "区域管理_区域类型_161_Menu")
    @ResourceAuth(value = "projectAreaTypeManager", type = AuthType.Project, remark = "区域管理_区域类型_161_Menu")
    @ResourceAuth(value = "projectAreaTypeManager", type = AuthType.School, remark = "区域管理_区域类型_161_Menu")
    @ResourceAuth(value = "projectAreaTypeManager", type = AuthType.BusinessMain, remark = "区域管理_区域类型_161_Menu")
    @ResourceAuth(value = "projectAreaTypeManager", type = AuthType.CommonOrg, remark = "区域管理_区域类型_161_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 = {"areaTypePageManager"}, method = {RequestMethod.POST})
    public ResultContent<Page<DictInfoParam>> areaTypePageManager(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable, @Parameter(required = false) DictInfoSearch param) {
        param.setDictInfoType(DictInfoType.AreaType);
        return dictInfoService.page(param, pageable);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "添加-编辑区域类型", description = "添加-编辑区域类型")
    @RequestMapping(value = "addAreaType", method = {RequestMethod.POST})
    public ResultContent addAreaType(@RequestBody DictInfoParam param) {
        param.setDictInfoType(DictInfoType.AreaType);
        return this.dictInfoService.addDict(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "删除区域类型", description = "删除区域类型")
    @RequestMapping(value = "deleteAreaType", method = {RequestMethod.POST})
    public ResultContent deleteAreaType(@RequestBody IDParam param) {
        return this.dictInfoService.deleteDict(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "区域类型详情", description = "区域类型详情")
    @RequestMapping(value = "getAreaType", method = {RequestMethod.POST})
    public ResultContent<DictInfoParam> getAreaType(@RequestBody IDParam param) {
        return this.dictInfoService.getDictInfo(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "查询区域类型所有的数据", description = "查询区域类型所有的数据")
    @RequestMapping(value = {"findAreaTypeByOid"}, method = {RequestMethod.POST})
    public ResultContent<List<DictInfoParam>> findAreaTypeByOid(@Parameter(required = false) DictInfoSearch param) {
        param.setDictInfoType(DictInfoType.AreaType);
        return dictInfoService.findDictInfosByOid(param);
    }

}
