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("positionManager")
@Tag(name = "机构职位管理")
public class PositionManagerController {

    @Autowired
    DictInfoService dictInfoService;

//    @ResourceAuth(value = "positionList", type = AuthType.Platform, remark = "职位管理_职位列表_1_Menu")
//    @ResourceAuth(value = "positionList", type = AuthType.Project, remark = "职位管理_职位列表_1_Menu")
//    @ResourceAuth(value = "positionList", 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 = "")
    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "机构职位列表-分页查询", description = "人员职位列表-分页查询")
    @RequestMapping(value = {"positionPageManager"}, method = {RequestMethod.POST})
    public ResultContent<Page<DictInfoParam>> positionPageManager(
            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
            @Parameter(required = false) DictInfoSearch param) {
        param.setDictInfoType(DictInfoType.Position);
        return dictInfoService.page(param, pageable);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "添加-编辑职位", description = "添加-编辑职位")
    @RequestMapping(value = "addPosition", method = {RequestMethod.POST})
    public ResultContent addPosition(@RequestBody DictInfoParam param) {
        param.setDictInfoType(DictInfoType.Position);
        return this.dictInfoService.addDict(param);
    }

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

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

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

}
