package cn.stylefeng.team.form.api.entity;

import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.roses.kernel.rule.util.sort.GetSortKey;
import cn.stylefeng.team.form.api.entity.data.FormItemDataLoad;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class FormItem implements GetSortKey {

    @ChineseDescription("表单元素id")
    private Long itemId;

    @ChineseDescription("所属表单组件的编码")
    private String componentCode;

    @ChineseDescription("权限编码")
    private String permissionCode;

    @ChineseDescription("是否绑定字段：true-绑定字段，false-不绑定字段")
    private Boolean bindFieldFlag = true;

    @ChineseDescription("自检绑定字段所属的数据表，例如：sys_user")
    private String metaModelCode;

    @ChineseDescription("组件绑定的字段编码，例如：userName")
    private String fieldCode;

    @ChineseDescription("数据加载的配置")
    private FormItemDataLoad formItemDataLoad;

    @ChineseDescription("针对下拉框的选择详情")
    private FormItemSelect formItemSelect;

    @ChineseDescription("针对table属性的特殊配置")
    private FormItemTable formItemTable;

    @ChineseDescription("视图选择器配置")
    private FormItemView formItemView;

    @ChineseDescription("元素标签名称")
    private String itemLabelName;

    @ChineseDescription("元素标签是否显示：true-显示，false-不显示")
    private Boolean itemLabelShowFlag = true;

    @ChineseDescription("元素字段占比：12-二分之一，8-三分之一，6-四分之一，16-三分之二，24-整行")
    private Integer itemColumnNumber;

    @ChineseDescription("是否开启注释：true-开启，false-不开启")
    private Boolean itemTipFlag = false;

    @ChineseDescription("注释内容")
    private String itemTipContent;

    @ChineseDescription("表单样式配置")
    private FormItemStyle formItemStyle;

    @ChineseDescription("是否隐藏：true-隐藏，false-非隐藏")
    private Boolean itemHiddenFlag = false;

    @ChineseDescription("占位符文本设置")
    private String placeholderContent;

    @ChineseDescription("字段是否可编辑：true-可编辑，false-只读")
    private Boolean itemEditFlag = true;

    @ChineseDescription("是否多选：true-多选，false-非多选")
    private Boolean itemMultipleChoiceFlag = false;

    @ChineseDescription("针对纯文本组件和分割线组件的配置")
    private FormItemContent formItemContent;

    @ChineseDescription("步骤条的配置")
    private List<FormItemStep> formItemStep;

    @ChineseDescription("表单元素，轮播图配置")
    private List<FormItemCarousel> formItemCarouselList;

    @ChineseDescription("表单面包屑组件配置")
    private List<FormItemBreadcrumb> formItemBreadcrumbList;

    @ChineseDescription("表单弹框组件的配置")
    private FormItemDialog formItemDialog;

    @ChineseDescription("日期选择组件配置")
    private FormItemDate formItemDate;

    @ChineseDescription("栅格布局的配置：栅格间距")
    private Integer gutter;

    @ChineseDescription("针对item组件的事件代码配置")
    private FormItemEvent formItemEvent;

    @ChineseDescription("必填项：true-必填，false-非必填")
    private Boolean itemRequiredFlag = false;

    private Integer contentValidateType;

    @ChineseDescription("常用格式校验：10-手机号码，20-邮箱，30-身份证，40-网址，50-银行卡，60-金额，70-纯数字，80-纯英文，90-纯中文")
    private Integer formatType;

    @ChineseDescription("正则表达式的值")
    private String regexExpression;

    @ChineseDescription("JS校验的代码")
    private String jsValidateCode;

    @ChineseDescription("校验逻辑后台接口地址")
    private String backendValidateUrl;

    @ChineseDescription("后台校验的接口参数名")
    private String backendValidateParamName;

    @ChineseDescription("自定义校验错误的提示")
    private String validateErrorTip;

    @ChineseDescription("针对数字组件的配置")
    private FormItemNumber formItemNumber;

    @ChineseDescription("针对文件信息的校验")
    private FormItemFile formItemFile;

    @ChineseDescription("组件高度，单位：px")
    private Integer itemHeight;

    @ChineseDescription("排序")
    private BigDecimal fldSort;

    @ChineseDescription("视图配置")
    private FormViewConfig formViewConfig;

    @ChineseDescription("子组件配置")
    private List<FormItem> children = new ArrayList<>();

    @Override
    public Object getSortKey() {
        return this.itemId;
    }
}
