package cn.ey.biz.module.system.api.dict;

import cn.ey.biz.common.pojo.R;
import cn.ey.biz.module.system.api.dict.dto.CategoryDataDTO;
import cn.ey.biz.module.system.api.dict.dto.DictDataRespDTO;
import cn.ey.biz.module.system.enums.ApiConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Collection;
import java.util.List;

@FeignClient(name = ApiConstants.NAME)
@Api(tags = "RPC 服务 - 字典数据")
public interface DictDataApi {

    String PREFIX = ApiConstants.PREFIX + "/dict-data";

    @GetMapping(PREFIX + "/valid")
    @ApiOperation("校验字典数据们是否有效")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictType", value = "字典类型", example = "SEX", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "values", value = "字典数据值的数组", example = "1,2", required = true, allowMultiple = true)
    })
    R<Boolean> validDictDatas(@RequestParam("dictType") String dictType,
                              @RequestParam("values") Collection<String> values);

    @GetMapping(PREFIX + "/get")
    @ApiOperation("获得指定的字典数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictType", value = "字典类型", example = "SEX", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "value", value = "字典数据值", example = "1", required = true, dataTypeClass = String.class)
    })
    R<DictDataRespDTO> getDictData(@RequestParam("dictType") String dictType,
                                   @RequestParam("value") String value);

    @GetMapping(PREFIX + "/parse")
    @ApiOperation("解析获得指定的字典数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictType", value = "字典类型", example = "SEX", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "label", value = "字典标签", example = "男", required = true, dataTypeClass = String.class)
    })
    R<DictDataRespDTO> parseDictData(@RequestParam("dictType") String dictType,
                                     @RequestParam("label") String label);

    @GetMapping(PREFIX + "/getbytype")
    @ApiOperation("根据字典类型获取全部字典项")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictType", value = "字典类型", example = "SEX", required = true, dataTypeClass = String.class)
    })
    R<List<CategoryDataDTO>> getDictDataByType(@RequestParam("dictType") String dictType);
}
