export type FieldType = "char"|"text"|"html"|"date"|"datetime"|"integer"|"float"|"boolean"|"binary"|"selection"|"one2many"|"many2one"|"many2many";

export abstract class FieldTypes {

    static CHAR: FieldType = "char";
    static TEXT: FieldType = "text";
    static HTML: FieldType = "html";
    static DATE: FieldType = "date";
    static DATETIME: FieldType = "datetime";
    static INTEGER: FieldType = "integer";
    static FLOAT: FieldType = "float";
    static BOOLEAN: FieldType = "boolean";
    static BINARY: FieldType = "binary";
    static SELECTION: FieldType = "selection";
    static ONE2MANY: FieldType = "one2many";
    static MANY2ONE: FieldType = "many2one";
    static MANY2MANY: FieldType = "many2many";

    /**
     *
     */
    static determineTypeFromFunction(type: Function): FieldType {
        if (type instanceof Date) {
            return FieldTypes.DATETIME;
        } else if (type instanceof Function) {
            const typeName = (<any>type).name.toLowerCase();
            switch (typeName) {
                case "char":
                    return FieldTypes.CHAR;
                case "text":
                    return FieldTypes.TEXT;
                case "html":
                    return FieldTypes.HTML;
                case "integer":
                    return FieldTypes.INTEGER;
                case "float":
                    return FieldTypes.FLOAT;
                case "boolean":
                    return FieldTypes.BOOLEAN;
                case "binary":
                    return FieldTypes.BINARY;
            }
        }

        // throw new Error(`El tipo ${type} no puede ser determinado`);
    }
}