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

metric_date: {
        type: DataTypes.DATE,
      
      

      },

streams: {
        type: DataTypes.INTEGER,
      
      

      },

unique_listeners: {
        type: DataTypes.INTEGER,
      
      

      },

saves: {
        type: DataTypes.INTEGER,
      
      

      },

likes: {
        type: DataTypes.INTEGER,
      
      

      },

shares: {
        type: DataTypes.INTEGER,
      
      

      },

country: {
        type: DataTypes.TEXT,
      
      

      },

city: {
        type: DataTypes.TEXT,
      
      

      },

traffic_source: {
        type: DataTypes.TEXT,
      
      

      },

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

  analytics_daily.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.analytics_daily.belongsTo(db.artist_profiles, {
      as: 'artist_profile',
      foreignKey: {
        name: 'artist_profileId',
      },
      constraints: false,
    });

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

    db.analytics_daily.belongsTo(db.releases, {
      as: 'release',
      foreignKey: {
        name: 'releaseId',
      },
      constraints: false,
    });

    db.analytics_daily.belongsTo(db.tracks, {
      as: 'track',
      foreignKey: {
        name: 'trackId',
      },
      constraints: false,
    });

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




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

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



  return analytics_daily;
};


