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

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.school.*;
import com.github.microservice.net.ResultContent;
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("dictInfo")
@Tag(name = "字典管理")
public class DictInfoController {

    @Autowired
    DictInfoService dictInfoService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "区域列表-分页查询", description = "区域列表-分页查询")
    @RequestMapping(value = {"areaPageManager"}, method = {RequestMethod.POST})
    public ResultContent<Page<DictInfoParam>> areaPageManager(@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 = {"page"}, method = {RequestMethod.POST})
    public ResultContent<Page<DictInfoParam>> page(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable, @Parameter(required = false) DictInfoSearch param) {
        return dictInfoService.page(param, pageable);
    }

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

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

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

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

}
