package com.ningdatech.pmapi.meta.controller;


import com.ningdatech.pmapi.meta.manage.MetaManage;
import com.ningdatech.pmapi.meta.model.po.ReqAddDictionaryPO;
import com.ningdatech.pmapi.meta.model.po.ReqDictionaryListPO;
import com.ningdatech.pmapi.meta.model.vo.ResDictionaryListVO;
import com.ningdatech.pmapi.meta.validate.DictionaryRequestValidator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author liuxinxin
 * @since 2022-07-21
 */
@RestController
@Validated
@RequiredArgsConstructor
@RequestMapping("/api/v1/meta/dictionary")
@Api(tags = "基础数据接口")
public class MetaDictionaryManageController {

    //    private final IMetaDictionaryManageService metaDictionaryManageService;
    private final MetaManage metaManage;

    @PostMapping("/list")
    @ApiOperation("字典筛选数据返回")
    public List<ResDictionaryListVO> expertDictList(@RequestBody ReqDictionaryListPO request) {
        DictionaryRequestValidator.dictionaryRequestValidator(request);
        return metaManage.getDictionaryList(request);
    }

    @PostMapping("/common/list")
    @ApiOperation("通用字典筛选数据返回")
    public List<ResDictionaryListVO> commonDictList(@RequestBody ReqDictionaryListPO request) {
        DictionaryRequestValidator.dictionaryRequestValidator(request);
        return metaManage.commonDictList(request);
    }

    @PostMapping("/add/dictionary")
    @ApiOperation("添加字典值")
    public void addDictionary(@Valid @RequestBody ReqAddDictionaryPO reqAddDictionaryPO) {
        metaManage.addDictionary(reqAddDictionaryPO);
    }

    @PostMapping("/remove/dictionary/{dictionaryCode}")
    @ApiOperation("删除字典值")
    public void removeDictionary(@PathVariable String dictionaryCode) {
        metaManage.removeDictionary(dictionaryCode);
    }

}
