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

export interface AiSummaryAttributes {
    id: string;
    applicationId: string;
    summaryType: string;
    summaryText: string;
    sentimentScore: number | null;
    recommendation: string | null;
}

export interface AiSummaryInstance extends Model<AiSummaryAttributes>, AiSummaryAttributes { }

export default (sequelize: Sequelize) => {
    const AiSummary = sequelize.define<AiSummaryInstance>('AiSummary', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true
        },
        applicationId: {
            type: DataTypes.UUID,
            allowNull: false,
            references: {
                model: 'applications',
                key: 'id'
            }
        },
        summaryType: {
            type: DataTypes.STRING,
            allowNull: false
        },
        summaryText: {
            type: DataTypes.TEXT,
            allowNull: false
        },
        sentimentScore: {
            type: DataTypes.DECIMAL(5, 2),
            allowNull: true
        },
        recommendation: {
            type: DataTypes.STRING,
            allowNull: true
        }
    }, {
        tableName: 'ai_summaries',
        timestamps: true,
        updatedAt: false,
        createdAt: 'generatedAt'
    });

    (AiSummary as any).associate = (models: any) => {
        AiSummary.belongsTo(models.Application, { foreignKey: 'applicationId', as: 'application' });
    };

    return AiSummary;
};
