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

direction: {
        type: DataTypes.ENUM,
        allowNull: false,
        defaultValue: 'forward',

        values: [

"forward",


"back",


"external"

        ],

      },

external_url: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

trigger_selector: {
        type: DataTypes.TEXT,
      
      

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
      indexes: [
        { fields: ['from_pageId'] },
        { fields: ['to_pageId'] },
        { fields: ['transitionId'] },
        { fields: ['is_active'] },
        { fields: ['deletedAt'] },
      ],
    },
  );

  page_links.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.page_links.belongsTo(db.tour_pages, {
      as: 'from_page',
      foreignKey: {
        name: 'from_pageId',
      },
      constraints: false,
    });

    db.page_links.belongsTo(db.tour_pages, {
      as: 'to_page',
      foreignKey: {
        name: 'to_pageId',
      },
      constraints: false,
    });

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




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

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



  return page_links;
};

