package cn.iocoder.yudao.module.member.controller.app.configdata;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.member.controller.admin.configdata.vo.ConfigDataRespVO;
import cn.iocoder.yudao.module.member.dal.dataobject.configdata.ConfigDataDO;
import cn.iocoder.yudao.module.member.service.configdata.ConfigDataService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 配置数据")
@RestController
@RequestMapping("/member/config-data")
@Validated
public class AppConfigDataController {

    @Resource
    private ConfigDataService configDataService;


    @GetMapping("/getList")
    @Operation(summary = "获得配置数据")
    public CommonResult<List<ConfigDataRespVO>> getConfigData(@RequestParam("dictType") String dictType) {
        List<ConfigDataDO> configData = configDataService.getConfigDataList(dictType);
        return success(BeanUtils.toBean(configData, ConfigDataRespVO.class));
    }

    @GetMapping("/getOne")
    @Operation(summary = "获得配置数据")
    public CommonResult<ConfigDataRespVO> getConfigData(@RequestParam("label") String label,@RequestParam("dictType") String dictType) {
        ConfigDataDO configData = configDataService.getConfigData(label, dictType);
        return success(BeanUtils.toBean(configData, ConfigDataRespVO.class));
    }


}