package cc.smtweb.framework.core.db.vo;

import lombok.Data;
import org.apache.commons.codec.digest.DigestUtils;

/**
 * 索引定义 {name:"索引名称，如idx_t1", fields:"字段，如f1,f2", type="索引类别：P-主键 I-一般索引 U-唯一索引"}
 */
@Data
public class ModelIndex {
    public static final String TYPE_PRIMARY = "P";
    public static final String TYPE_INDEX = "I";
    public static final String TYPE_UNIQUE = "U";

    private String type;
    private String fields;

    public boolean isUnique() {
        return TYPE_UNIQUE.equals(type);
    }

    public String getName() {
        return DigestUtils.md5Hex(fields).substring(0, 16);
    }
}
