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

name: {
        type: DataTypes.TEXT,
      
      

      },

category: {
        type: DataTypes.ENUM,
      
      

        values: [

"streaming",


"social",


"other"

        ],

      },

website_url: {
        type: DataTypes.TEXT,
      
      

      },

is_active: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  distribution_platforms.associate = (db) => {


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

















    db.distribution_platforms.hasMany(db.release_deliveries, {
      as: 'release_deliveries_platform',
      foreignKey: {
          name: 'platformId',
      },
      constraints: false,
    });



    db.distribution_platforms.hasMany(db.smart_link_destinations, {
      as: 'smart_link_destinations_platform',
      foreignKey: {
          name: 'platformId',
      },
      constraints: false,
    });


    db.distribution_platforms.hasMany(db.smart_link_clicks, {
      as: 'smart_link_clicks_platform',
      foreignKey: {
          name: 'platformId',
      },
      constraints: false,
    });


    db.distribution_platforms.hasMany(db.playlists, {
      as: 'playlists_platform',
      foreignKey: {
          name: 'platformId',
      },
      constraints: false,
    });




    db.distribution_platforms.hasMany(db.royalty_reports, {
      as: 'royalty_reports_platform',
      foreignKey: {
          name: 'platformId',
      },
      constraints: false,
    });








    db.distribution_platforms.hasMany(db.analytics_daily, {
      as: 'analytics_daily_platform',
      foreignKey: {
          name: 'platformId',
      },
      constraints: false,
    });














//end loop



    db.distribution_platforms.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });



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


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

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



  return distribution_platforms;
};


