package com.agileboot.system.config.vo;

import cn.hutool.core.convert.Convert;
import cn.hutool.json.JSONUtil;
import com.agileboot.common.core.enums.BasicEnumUtil;
import com.agileboot.common.core.enums.common.YesOrNoEnum;
import com.agileboot.system.config.entity.SysConfig;
import lombok.Data;

import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @author valarchie
 */
@Data
public class ConfigVO {

    private Long configId;
    private String configName;
    private String configKey;
    private String configValue;
    private List<String> configOptions;
    private Integer isAllowChange;
    private String isAllowChangeStr;
    private String remark;
    private Date createTime;

    public ConfigVO(SysConfig entity) {
        if (entity != null) {
            configId = entity.getId();
            configName = entity.getConfigName();
            configKey = entity.getConfigKey();
            configValue = entity.getConfigValue();
            configOptions =
                    JSONUtil.isTypeJSONArray(entity.getConfigOptions()) ? JSONUtil.toList(entity.getConfigOptions(),
                            String.class) : Collections.emptyList();
            isAllowChange = Convert.toInt(entity.getIsAllowChange());
            isAllowChangeStr = BasicEnumUtil.getDescriptionByBool(YesOrNoEnum.class, entity.getIsAllowChange());
            remark = entity.getRemark();
            createTime = entity.getCreateTime();
        }
    }
}
