export default (sequelize, DataTypes) => {
    return sequelize.define('DomainManagement', {
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            autoIncrement: true
        },
        domain_name: {
            type: DataTypes.STRING,
            allowNull: false,
            unique: true,
            set(value) {
                this.setDataValue('domain_name', value.trim().toLowerCase());
            }
        },
        client_email: {
            type: DataTypes.STRING,
            allowNull: false,
            validate: {
                isEmail: true
            }
        },
        client_name: {
            type: DataTypes.STRING,
            allowNull: false
        },
        registrar: {
            type: DataTypes.STRING,
            allowNull: false
        },
        expiry_date: {
            type: DataTypes.DATEONLY,
            allowNull: false
        },
        status: {
            type: DataTypes.ENUM('active', 'expired', 'pending', 'inactive', 'renewed'),
            allowNull: false,
            defaultValue: 'active'
        },
        auto_renew: {
            type: DataTypes.BOOLEAN,
            allowNull: false,
            defaultValue: false
        },
        ssl_enabled: {
            type: DataTypes.BOOLEAN,
            allowNull: false,
            defaultValue: true
        },
        cost: {
            type: DataTypes.DECIMAL(10, 2),
            allowNull: false,
            defaultValue: 0
        },
        ssl_expiry_date: {
            type: DataTypes.DATEONLY,
            allowNull: true
        },
        last_renewed_at: {
            type: DataTypes.DATEONLY,
            allowNull: true
        },
        renewal_alert_sent_at: {
            type: DataTypes.DATE,
            allowNull: true
        },
        renewal_alert_for_expiry: {
            type: DataTypes.DATEONLY,
            allowNull: true
        },
        notes: {
            type: DataTypes.TEXT,
            allowNull: true
        },
        created_at: {
            type: DataTypes.DATE,
            allowNull: false,
            defaultValue: DataTypes.NOW
        }
    }, {
        tableName: 'domain_management',
        timestamps: false
    });
};
