export default (sequelize, DataTypes) => {
    return sequelize.define('Hosting', {
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            autoIncrement: true
        },
        client_name: {
            type: DataTypes.STRING,
            allowNull: false
        },
        client_email: {
            type: DataTypes.STRING,
            allowNull: false,
            validate: {
                isEmail: true
            }
        },
        domain_name: {
            type: DataTypes.STRING,
            allowNull: false,
            unique: true,
            set(value) {
                this.setDataValue('domain_name', value.trim().toLowerCase());
            }
        },
        cost: {
            type: DataTypes.DECIMAL(10, 2),
            allowNull: false,
            defaultValue: 0
        },
 
        start_date: {
            type: DataTypes.DATEONLY,
            allowNull: true
        },
        renewal_date: {
            type: DataTypes.DATEONLY,
            allowNull: false
        },
        status: {
            type: DataTypes.ENUM('active', 'expiring', 'suspended', 'expired', 'pending'),
            allowNull: false,
            defaultValue: 'active'
        },
        auto_renew: {
            type: DataTypes.BOOLEAN,
            allowNull: false,
            defaultValue: false
        },
        last_renewed_at: {
            type: DataTypes.DATEONLY,
            allowNull: true
        },
        reminder_sent_at: {
            type: DataTypes.DATE,
            allowNull: true
        },
        reminder_for_renewal: {
            type: DataTypes.DATEONLY,
            allowNull: true
        },

        created_at: {
            type: DataTypes.DATE,
            allowNull: false,
            defaultValue: DataTypes.NOW
        },
        updated_at: {
            type: DataTypes.DATE,
            allowNull: false,
            defaultValue: DataTypes.NOW
        }
    },
        {
            tableName: 'hostings',
            timestamps: false
        }

    );
};

