export default (sequelize, DataTypes) => {
    return sequelize.define('Settings', {

        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            autoIncrement: true
        },

        name: {
            type: DataTypes.STRING,
            allowNull: false,
            validate: {
                notEmpty: { msg: "Name is required" },
                noDigits(value) {
                    if (/\d/.test(value)) {
                        throw new Error("Name must not contain numbers");
                    }
                }
            }
        },

        email: {
            type: DataTypes.STRING,
            allowNull: false,
            unique: true,        
            validate: {
                isEmail: { msg: "Please provide a valid email address" },
                notEmpty: { msg: "Email is required" }
            }
        },

        phone: {
            type: DataTypes.STRING(20),
            allowNull: false,
            validate: {
                notEmpty: { msg: "Phone is required" },
                isValidPhone(value) {
                    if (!/^\+91\s\d{5}\s\d{5}$/.test(value)) {
                        throw new Error("Phone must be in format: +91 XXXXX XXXXX");
                    }
                }
            }
        },

        password: {
            type: DataTypes.STRING,
            allowNull: false,
            validate: {
                notEmpty: { msg: "Password is required" },
                len: {
                    args: [6, 100],
                    msg: "Password must be at least 6 characters long"
                }
            }
        },

        role: {
            type: DataTypes.STRING(100),
            allowNull: true
        },

        avatar: {
            type: DataTypes.STRING,        
            allowNull: true
        },

        company_name: {
            type: DataTypes.STRING,
            allowNull: true
        },

        company_address: {
            type: DataTypes.STRING,
            allowNull: true
        },

        company_logo: {
            type: DataTypes.STRING,
            allowNull: true
        },

        tax_id: {
            type: DataTypes.STRING,
            allowNull: true
        },

        currency: {
            type: DataTypes.STRING(100),
            allowNull: true
        },

        smtp_host: {
            type: DataTypes.STRING,
            allowNull: true
        },

        smtp_port: {
            type: DataTypes.INTEGER,
            allowNull: true
        },

        smtp_user: {
            type: DataTypes.STRING,
            allowNull: true
        },

        smtp_pass: {
            type: DataTypes.STRING,
            allowNull: true
        },

        smtp_secure: {
            type: DataTypes.BOOLEAN,
            allowNull: true,
            defaultValue: true
        },

        smtp_from_email: {
            type: DataTypes.STRING,
            allowNull: true
        },

        smtp_from_name: {
            type: DataTypes.STRING,
            allowNull: true
        },
        title: {
            type: DataTypes.STRING,
            allowNull: true
        }

    }, {
        tableName: 'settings',
        timestamps: false
    });
};