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 store_pages = sequelize.define(
    'store_pages',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

page_title: {
        type: DataTypes.TEXT,
      
      

      },

slug: {
        type: DataTypes.TEXT,
      
      

      },

page_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"landing",


"product_list",


"faq",


"policy",


"custom"

        ],

      },

page_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"published",


"archived"

        ],

      },

content: {
        type: DataTypes.TEXT,
      
      

      },

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

  store_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.store_pages.belongsTo(db.reseller_stores, {
      as: 'reseller_store',
      foreignKey: {
        name: 'reseller_storeId',
      },
      constraints: false,
    });

    db.store_pages.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });



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


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

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



  return store_pages;
};


