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

export interface InterviewParticipantAttributes {
    id: string;
    interviewId: string;
    userId: string;
    roleInPanel: string | null;
}

export interface InterviewParticipantInstance extends Model<InterviewParticipantAttributes>, InterviewParticipantAttributes { }

export default (sequelize: Sequelize) => {
    const InterviewParticipant = sequelize.define<InterviewParticipantInstance>('InterviewParticipant', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true
        },
        interviewId: {
            type: DataTypes.UUID,
            allowNull: false,
            references: {
                model: 'interviews',
                key: 'id'
            }
        },
        userId: {
            type: DataTypes.UUID,
            allowNull: false,
            references: {
                model: 'users',
                key: 'id'
            }
        },
        roleInPanel: {
            type: DataTypes.STRING,
            allowNull: true
        }
    }, {
        tableName: 'interview_participants',
        timestamps: true,
        updatedAt: false
    });

    (InterviewParticipant as any).associate = (models: any) => {
        InterviewParticipant.belongsTo(models.Interview, { foreignKey: 'interviewId', as: 'interview' });
        InterviewParticipant.belongsTo(models.User, { foreignKey: 'userId', as: 'user' });
    };

    return InterviewParticipant;
};
