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

target_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"product",


"category",


"page"

        ],

      },

target_slug: {
        type: DataTypes.TEXT,
      
      

      },

meta_title: {
        type: DataTypes.TEXT,
      
      

      },

meta_description: {
        type: DataTypes.TEXT,
      
      

      },

canonical_url: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  seo_entries.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.seo_entries.belongsTo(db.products, {
      as: 'product',
      foreignKey: {
        name: 'productId',
      },
      constraints: false,
    });

    db.seo_entries.belongsTo(db.categories, {
      as: 'category',
      foreignKey: {
        name: 'categoryId',
      },
      constraints: false,
    });

    db.seo_entries.belongsTo(db.cms_pages, {
      as: 'page',
      foreignKey: {
        name: 'pageId',
      },
      constraints: false,
    });




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

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



  return seo_entries;
};


