module.exports = function(sequelize, DataTypes) {
  const publish_events = sequelize.define(
    'publish_events',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

title: {
        type: DataTypes.STRING,
        allowNull: true,

      },

description: {
        type: DataTypes.TEXT,
        allowNull: true,

      },

from_environment: {
        type: DataTypes.ENUM,
        allowNull: false,

        values: [

"dev",


"stage",


"production"

        ],

      },

to_environment: {
        type: DataTypes.ENUM,
        allowNull: false,

        values: [

"dev",


"stage",


"production"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

finished_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
        allowNull: false,
        defaultValue: 'queued',

        values: [

"queued",


"running",


"success",


"failed"

        ],

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

pages_copied: {
        type: DataTypes.INTEGER,
      
      

      },

transitions_copied: {
        type: DataTypes.INTEGER,
      
      

      },

audios_copied: {
        type: DataTypes.INTEGER,
      
      

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
      indexes: [
        { fields: ['projectId'] },
        { fields: ['userId'] },
        { fields: ['status'] },
        { fields: ['started_at'] },
      ],
    },
  );

  publish_events.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity



















//end loop



    db.publish_events.belongsTo(db.projects, {
      as: 'project',
      foreignKey: {
        name: 'projectId',
      },
      constraints: false,
    });

    db.publish_events.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });




    db.publish_events.belongsTo(db.users, {
      as: 'createdBy',
    });

    db.publish_events.belongsTo(db.users, {
      as: 'updatedBy',
    });
  };



  return publish_events;
};
