package com.ruoyi.business.domain;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 模版属性对象 business_template_prop
 * 
 * @author ruoyi
 * @date 2024-03-31
 */
@Data
public class BusinessTemplateProp extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    
    /** 标题 */
    @Excel(name = "标题")
    private String title;


    /** 组件类型（0单选框 1多选框） */
    @Excel(name = "组件类型", readConverterExp = "0=单选框,1=多选框")
    private String compType;


    /** 字段名 */
    @Excel(name = "字段名")
    private String fieldName;


    /** 占位提示 */
    @Excel(name = "占位提示")
    private String placPrompt;


    /** 默认值 */
    @Excel(name = "默认值")
    private String defaultValue;


    /** 可选值 */
    @Excel(name = "可选值")
    private String optionalValue;

    /** 可选值数组 */
    @Excel(name = "可选值数组")
    @TableField(exist = false)
    private List<Map<String,Object>> optionalValues = new ArrayList<Map<String,Object>>();

    /** 是否开放 */
    @Excel(name = "是否开放")
    private String open;


    /** 模版id */
    @Excel(name = "模版id")
    private Long tempId;

    /** 排序 */
    @Excel(name = "排序")
    private Integer sort;

    public void setTitle(String title) 
    {
        this.title = title;
    }

    public String getTitle() 
    {
        return title;
    }
    public void setCompType(String compType) 
    {
        this.compType = compType;
    }

    public String getCompType() 
    {
        return compType;
    }
    public void setFieldName(String fieldName) 
    {
        this.fieldName = fieldName;
    }

    public String getFieldName() 
    {
        return fieldName;
    }
    public void setPlacPrompt(String placPrompt) 
    {
        this.placPrompt = placPrompt;
    }

    public String getPlacPrompt() 
    {
        return placPrompt;
    }
    public void setDefaultValue(String defaultValue) 
    {
        this.defaultValue = defaultValue;
    }

    public String getDefaultValue() 
    {
        return defaultValue;
    }
    public void setOptionalValue(String optionalValue) 
    {
        if(StringUtils.isNotBlank(optionalValue)){
            String[] split = optionalValue.split("\\|");

            for (String s : split) {
               Map<String, Object> dataMap = new HashMap<>();
                String[] value = s.split(",");
                dataMap.put("key",value[0]);
                dataMap.put("value",value[1]);
                this.optionalValues.add(dataMap);
            }

        }
        this.optionalValue = optionalValue;
    }

    public String getOptionalValue() 
    {
        return optionalValue;
    }
    public void setOpen(String open) 
    {
        this.open = open;
    }

    public String getOpen() 
    {
        return open;
    }
    public void setTempId(Long tempId) 
    {
        this.tempId = tempId;
    }

    public Long getTempId() 
    {
        return tempId;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("id", getId())
            .append("title", getTitle())
            .append("compType", getCompType())
            .append("fieldName", getFieldName())
            .append("placPrompt", getPlacPrompt())
            .append("defaultValue", getDefaultValue())
            .append("optionalValue", getOptionalValue())
            .append("open", getOpen())
            .append("tempId", getTempId())
            .append("createBy", getCreateBy())
            .append("createTime", getCreateTime())
            .append("updateBy", getUpdateBy())
            .append("updateTime", getUpdateTime())
            .append("deleted", getDeleted())
            .append("remark", getRemark())
            .toString();
    }

}
