export const defaultPermissions = {
    dashboard: { view: false },
    user: { view: false },
    accountant: { view: false },
    invoice: { view: false },
    bill: { view: false },
    salary: { view: false },
    expenses: { view: false },
    enquiry: { view: false },
    domain: { view: false },
    hosting: { view: false },
    settings: { view: false }
};

export default (sequelize, DataTypes) => {
    return sequelize.define('User', {
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            autoIncrement: true
        },
        name: {
            type: DataTypes.STRING,
            allowNull: false
        },
        email: {
            type: DataTypes.STRING,
            allowNull: false,
            unique: true,
            set(value) {
                this.setDataValue('email', value.trim().toLowerCase());
            },
            validate: {
                isEmail: true
            }
        },
        password: {
            type: DataTypes.STRING,
            allowNull: false
        },
        role: {
            type: DataTypes.STRING,
            allowNull: false,
            defaultValue: 'user',
            validate: {
                isIn: [['admin', 'accountant', 'user', 'staff', 'manager']]
            }
        },
        status: {
            type: DataTypes.STRING,
            allowNull: false,
            defaultValue: 'active',
            validate: {
                isIn: [['active', 'inactive', 'blocked']]
            }
        },
        avatar: {
            type: DataTypes.STRING,
            allowNull: true
        },
        permissions: {
            type: DataTypes.JSON,
            allowNull: false,
            defaultValue: () => JSON.parse(JSON.stringify(defaultPermissions))
        },
        created_at: {
            type: DataTypes.DATE,
            allowNull: false,
            defaultValue: DataTypes.NOW
        }
    },
        {
            tableName: 'users',
            timestamps: false
        }
    );
}
