import { Model, DataTypes, Sequelize } from 'sequelize';

export interface SLAReminderAttributes {
    id: string;
    slaConfigId: string;
    timeValue: number;
    timeUnit: 'hours' | 'days';
    isEnabled: boolean;
}

export interface SLAReminderInstance extends Model<SLAReminderAttributes>, SLAReminderAttributes { }

export default (sequelize: Sequelize) => {
    const SLAReminder = sequelize.define<SLAReminderInstance>('SLAReminder', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true
        },
        slaConfigId: {
            type: DataTypes.UUID,
            allowNull: false,
            references: {
                model: 'sla_configurations',
                key: 'id'
            }
        },
        timeValue: {
            type: DataTypes.INTEGER,
            allowNull: false
        },
        timeUnit: {
            type: DataTypes.ENUM('hours', 'days'),
            allowNull: false
        },
        isEnabled: {
            type: DataTypes.BOOLEAN,
            defaultValue: true
        }
    }, {
        tableName: 'sla_config_reminders',
        timestamps: true,
        indexes: [
            { fields: ['slaConfigId'] }
        ]
    });

    (SLAReminder as any).associate = (models: any) => {
        SLAReminder.belongsTo(models.SLAConfiguration, {
            foreignKey: 'slaConfigId',
            as: 'slaConfig'
        });
    };

    return SLAReminder;
};
