const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');

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

title: {
        type: DataTypes.TEXT,
      
      

      },

slug: {
        type: DataTypes.TEXT,
      
      

      },

page_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"home",


"rooms",


"about",


"contact",


"privacy",


"terms",


"faq",


"custom"

        ],

      },

content: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

published_at: {
        type: DataTypes.DATE,
      
      

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  content_pages.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.content_pages.belongsTo(db.hotels, {
      as: 'hotel',
      foreignKey: {
        name: 'hotelId',
      },
      constraints: false,
    });

    db.content_pages.belongsTo(db.users, {
      as: 'author',
      foreignKey: {
        name: 'authorId',
      },
      constraints: false,
    });



    db.content_pages.hasMany(db.file, {
      as: 'hero_images',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.content_pages.getTableName(),
        belongsToColumn: 'hero_images',
      },
    });


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

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



  return content_pages;
};


