"use strict";
const Sequelize = require("sequelize");

/*const getStateText = (inscription) => {
  if (inscription.type !== "online" && inscription !== "online group") {
    if (inscription.validated == true) {
      return "Inscripción confirmada";
    } else if (inscription.overflowEventId) {
      return "Inscripción confirmada a lista de espera";
    } else if (inscription.reservationId) {
      return "Inscripción confirmada a lista de espera de tu reserva";
    } else return "N/A";
  } else {
    // online
    return "Inscripción online confirmada";
  }
};
*/
module.exports = function (sequelize, DataTypes) {
  const EventInscriptionOnline = sequelize.define(
    "EventInscriptionOnline",
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },
      eventId: {
        type: DataTypes.UUID,
        //        foreignKey: true,
      },
      userId: {
        type: DataTypes.UUID,
        //        foreignKey: true,
      },
      date: {
        type: DataTypes.DATE,
      },
      email: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      name: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      surname: {
        type: DataTypes.STRING,
      },
      entity_name: {
        type: DataTypes.STRING,
      },
      assistants: {
        type: DataTypes.INTEGER,
      },
      profile: {
        type: DataTypes.STRING,
      },

    },
    {
      tableName: "v_events_inscriptions_online",
      freezeTableName: true,
      timestamps: false,

      defaultScope: {
        order: [["date", "DESC"]],
        //      include: [
        //        {
        //          model: sequelize.models.User,
        //          as: "user",
        //          include: [{ model: sequelize.models.Entity, attributes: ["id", "name"], required: false }],
        //        },
        //      ],
      },
    }
  );

  EventInscriptionOnline.associate = function (models) {
    EventInscriptionOnline.Event = EventInscriptionOnline.belongsTo(models.Event, { foreignKey: "eventId", as: "event" });
    //    EventInscriptionOnline.User = EventInscriptionOnline.belongsTo(models.User, { foreignKey: "userId", as: "user" });
  };

  return EventInscriptionOnline;
};
