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

creative_name: {
        type: DataTypes.TEXT,
      
      

      },

creative_format: {
        type: DataTypes.ENUM,
      
      

        values: [

"image",


"video",


"carousel",


"text",


"landing_page_section",


"email"

        ],

      },

primary_text: {
        type: DataTypes.TEXT,
      
      

      },

headline: {
        type: DataTypes.TEXT,
      
      

      },

description_text: {
        type: DataTypes.TEXT,
      
      

      },

call_to_action: {
        type: DataTypes.TEXT,
      
      

      },

targeting_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  ad_creatives.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.ad_creatives.belongsTo(db.ad_projects, {
      as: 'ad_project',
      foreignKey: {
        name: 'ad_projectId',
      },
      constraints: false,
    });



    db.ad_creatives.hasMany(db.file, {
      as: 'creative_images',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.ad_creatives.getTableName(),
        belongsToColumn: 'creative_images',
      },
    });

    db.ad_creatives.hasMany(db.file, {
      as: 'creative_files',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.ad_creatives.getTableName(),
        belongsToColumn: 'creative_files',
      },
    });


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

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



  return ad_creatives;
};


