package com.tashow.cloud.system.controller.app.dict;

import static com.tashow.cloud.common.pojo.CommonResult.success;

import com.tashow.cloud.common.enums.CommonStatusEnum;
import com.tashow.cloud.common.pojo.CommonResult;
import com.tashow.cloud.common.util.object.BeanUtils;
import com.tashow.cloud.system.controller.app.dict.vo.AppDictDataRespVO;
import com.tashow.cloud.system.dal.dataobject.dict.DictDataDO;
import com.tashow.cloud.system.service.dict.DictDataService;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import java.util.List;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/** 用户 App - 字典数据 */
@RestController
@RequestMapping("/system/dict-data")
@Validated
public class AppDictDataController {

  @Resource private DictDataService dictDataService;

  /** 根据字典类型查询字典数据信息 */
  @GetMapping("/type")
  @PermitAll
  public CommonResult<List<AppDictDataRespVO>> getDictDataListByType(
      @RequestParam("type") String type) {
    List<DictDataDO> list =
        dictDataService.getDictDataList(CommonStatusEnum.ENABLE.getStatus(), type);
    return success(BeanUtils.toBean(list, AppDictDataRespVO.class));
  }
}
