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

name: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"planning",


"active",


"paused",


"completed",


"archived"

        ],

      },

start_date: {
        type: DataTypes.DATE,
      
      

      },

end_date: {
        type: DataTypes.DATE,
      
      

      },

budget: {
        type: DataTypes.DECIMAL,
      
      

      },

goal: {
        type: DataTypes.TEXT,
      
      

      },

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

  content_campaigns.associate = (db) => {

    db.content_campaigns.belongsToMany(db.content_items, {
      as: 'content_items',
      foreignKey: {
        name: 'content_campaigns_content_itemsId',
      },
      constraints: false,
      through: 'content_campaignsContent_itemsContent_items',
    });

    db.content_campaigns.belongsToMany(db.content_items, {
      as: 'content_items_filter',
      foreignKey: {
        name: 'content_campaigns_content_itemsId',
      },
      constraints: false,
      through: 'content_campaignsContent_itemsContent_items',
    });

    db.content_campaigns.belongsToMany(db.seo_keywords, {
      as: 'keywords',
      foreignKey: {
        name: 'content_campaigns_keywordsId',
      },
      constraints: false,
      through: 'content_campaignsKeywordsSeo_keywords',
    });

    db.content_campaigns.belongsToMany(db.seo_keywords, {
      as: 'keywords_filter',
      foreignKey: {
        name: 'content_campaigns_keywordsId',
      },
      constraints: false,
      through: 'content_campaignsKeywordsSeo_keywords',
    });


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

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




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

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



  return content_campaigns;
};


