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

keyword: {
        type: DataTypes.TEXT,
      
      

      },

intent: {
        type: DataTypes.ENUM,
      
      

        values: [

"informational",


"commercial",


"transactional",


"navigational"

        ],

      },

difficulty: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"medium",


"high"

        ],

      },

search_volume: {
        type: DataTypes.INTEGER,
      
      

      },

cpc: {
        type: DataTypes.DECIMAL,
      
      

      },

target_url: {
        type: DataTypes.TEXT,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  seo_keywords.associate = (db) => {

    db.seo_keywords.belongsToMany(db.tags, {
      as: 'tags',
      foreignKey: {
        name: 'seo_keywords_tagsId',
      },
      constraints: false,
      through: 'seo_keywordsTagsTags',
    });

    db.seo_keywords.belongsToMany(db.tags, {
      as: 'tags_filter',
      foreignKey: {
        name: 'seo_keywords_tagsId',
      },
      constraints: false,
      through: 'seo_keywordsTagsTags',
    });


/// 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_keywords.belongsTo(db.companies, {
      as: 'company',
      foreignKey: {
        name: 'companyId',
      },
      constraints: false,
    });

    db.seo_keywords.belongsTo(db.business_units, {
      as: 'business_unit',
      foreignKey: {
        name: 'business_unitId',
      },
      constraints: false,
    });




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

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



  return seo_keywords;
};


