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

project_name: {
        type: DataTypes.TEXT,
      
      

      },

channel: {
        type: DataTypes.ENUM,
      
      

        values: [

"meta",


"google_search",


"google_display",


"tiktok",


"linkedin",


"youtube",


"email",


"landing_page"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"in_review",


"approved",


"scheduled",


"live",


"paused",


"completed"

        ],

      },

creative_brief: {
        type: DataTypes.TEXT,
      
      

      },

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

  ad_projects.associate = (db) => {


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









    db.ad_projects.hasMany(db.six_hat_sessions, {
      as: 'six_hat_sessions_ad_project',
      foreignKey: {
          name: 'ad_projectId',
      },
      constraints: false,
    });











    db.ad_projects.hasMany(db.ad_creatives, {
      as: 'ad_creatives_ad_project',
      foreignKey: {
          name: 'ad_projectId',
      },
      constraints: false,
    });


    db.ad_projects.hasMany(db.generation_runs, {
      as: 'generation_runs_ad_project',
      foreignKey: {
          name: 'ad_projectId',
      },
      constraints: false,
    });






    db.ad_projects.hasMany(db.platform_metrics, {
      as: 'platform_metrics_ad_project',
      foreignKey: {
          name: 'ad_projectId',
      },
      constraints: false,
    });






//end loop



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

    db.ad_projects.belongsTo(db.brand_voice_profiles, {
      as: 'brand_voice_profile',
      foreignKey: {
        name: 'brand_voice_profileId',
      },
      constraints: false,
    });




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

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



  return ad_projects;
};


