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

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

        values: [

"nav_button",


"spot",


"description",


"tooltip",


"gallery",


"carousel",


"logo",


"video_player",


"popup"

        ],

      },

name: {
        type: DataTypes.TEXT,
        validate: {
          len: { args: [0, 255], msg: 'Element name must be at most 255 characters' },
        },
      },

sort_order: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,

      },

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

      },

x_percent: {
        type: DataTypes.DECIMAL,
      
      

      },

y_percent: {
        type: DataTypes.DECIMAL,
      
      

      },

width_percent: {
        type: DataTypes.DECIMAL,
      
      

      },

height_percent: {
        type: DataTypes.DECIMAL,
      
      

      },

rotation_deg: {
        type: DataTypes.DECIMAL,
      
      

      },

style_json: {
        type: DataTypes.JSON,
      },

content_json: {
        type: DataTypes.JSON,
      },

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

  page_elements.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_elements.belongsTo(db.tour_pages, {
      as: 'page',
      foreignKey: {
        name: 'pageId',
        allowNull: false,
      },
      constraints: true,
      onDelete: 'CASCADE',
      onUpdate: 'CASCADE',
    });




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

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



  return page_elements;
};

