'use strict';

module.exports = function (sequelize, DataTypes) {
    const EventDetail = sequelize.define('EventDetail', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true
        },
        eventId: {
            type: DataTypes.UUID,
            allowNull: false,
        },
        speakerId: {
            type: DataTypes.UUID,
        },
        order: {
            type: DataTypes.INTEGER,
            allowNull: false,
        },
        description: {
            type: DataTypes.STRING,
        },   
        type: {
            type: DataTypes.STRING,
            default: 'detail',            //info, speaker, schedule, detail
        }     
    }, {
            indexes: [{
                unique: false,
                fields: ['speakerId']
            }],
            tableName: 'events_details',
            freezeTableName: true,
            timestamps: true,
        });

    EventDetail.associate = function (models) {
        EventDetail.Event = EventDetail.belongsTo(models.Event, { foreignKey: 'eventId', as: "event" });
        EventDetail.Speaker = EventDetail.belongsTo(models.Speaker, {foreignKey: 'speakerId', as: "speaker"});
    };


    return EventDetail;
};