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

campaign_name: {
        type: DataTypes.TEXT,
      
      

      },

campaign_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"awareness",


"lead_gen",


"conversion",


"retargeting",


"partnerships",


"education"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"planned",


"active",


"paused",


"completed",


"archived"

        ],

      },

objective: {
        type: DataTypes.TEXT,
      
      

      },

primary_audience: {
        type: DataTypes.TEXT,
      
      

      },

budget_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

budget_currency: {
        type: DataTypes.TEXT,
      
      

      },

start_at: {
        type: DataTypes.DATE,
      
      

      },

end_at: {
        type: DataTypes.DATE,
      
      

      },

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

  campaigns.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity









    db.campaigns.hasMany(db.six_hat_sessions, {
      as: 'six_hat_sessions_campaign',
      foreignKey: {
          name: 'campaignId',
      },
      constraints: false,
    });







    db.campaigns.hasMany(db.campaign_brain_configs, {
      as: 'campaign_brain_configs_campaign',
      foreignKey: {
          name: 'campaignId',
      },
      constraints: false,
    });




    db.campaigns.hasMany(db.ad_projects, {
      as: 'ad_projects_campaign',
      foreignKey: {
          name: 'campaignId',
      },
      constraints: false,
    });







    db.campaigns.hasMany(db.learning_signals, {
      as: 'learning_signals_campaign',
      foreignKey: {
          name: 'campaignId',
      },
      constraints: false,
    });







//end loop



    db.campaigns.belongsTo(db.brands, {
      as: 'brand',
      foreignKey: {
        name: 'brandId',
      },
      constraints: false,
    });




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

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



  return campaigns;
};


