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

environment: {
        type: DataTypes.ENUM,
        allowNull: false,
        defaultValue: 'dev',

        values: [

"dev",


"stage",


"production"

        ],

      },

source_key: {
        type: DataTypes.TEXT,
      
      

      },

name: {
        type: DataTypes.TEXT,
        allowNull: false,

      },

slug: {
        type: DataTypes.TEXT,
        allowNull: false,

      },

video_url: {
        type: DataTypes.TEXT,
      
      

      },

audio_url: {
        type: DataTypes.TEXT,
      
      

      },

supports_reverse: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

duration_sec: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  transitions.associate = (db) => {


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












    db.transitions.hasMany(db.page_links, {
      as: 'page_links_transition',
      foreignKey: {
          name: 'transitionId',
      },
      constraints: false,
    });








//end loop



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




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

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



  return transitions;
};

