package org.anyline.data.dify.entity;

import org.anyline.entity.DataRow;
import org.anyline.entity.OriginRow;
import org.anyline.metadata.Column;
import org.anyline.util.BeanUtil;

import java.io.Serializable;

public class Metadata extends Column implements Serializable {
    private static final long serialVersionUID = 1L;
    private String type;

    public Metadata(){}

    /**
     * 知识库添加元数据定义时用到
     * @param name 名称
     * @param type 类型 string number datetime
     */
    public Metadata(String name, String type){
        this.name = name;
        this.type = type;
    }

    /**
     * 文档添加元数据值时用到
     * @param id 与知识库添加元数据定义时返回的id保持一致
     * @param name 名称
     * @param value 值
     */
    public Metadata(String id, String name, Object value){
        this.id = id;
        this.name = name;
        this.value = value;
    }


    public DataRow map(){
        return map(true);
    }
    public DataRow map(boolean empty) {
        DataRow row = new OriginRow();
        row.put("id", id);
        row.put("name", name);
        row.put("value", value);
        row.put("type", type);
        return row;
    }
    public String json(){
        return BeanUtil.map2string(map());
    }
    public String json(boolean empty){
        return BeanUtil.map2string(map(empty));
    }

    public String getType() {
        return type;
    }

    public Column setType(String type) {
        this.type = type;
        return this;
    }
}
