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

territory: {
        type: DataTypes.TEXT,
      
      

      },

store_name: {
        type: DataTypes.TEXT,
      
      

      },

quantity: {
        type: DataTypes.INTEGER,
      
      

      },

unit_rate: {
        type: DataTypes.DECIMAL,
      
      

      },

gross_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

net_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

event_at: {
        type: DataTypes.DATE,
      
      

      },

usage_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"stream",


"download",


"video",


"ugc",


"content_id",


"other"

        ],

      },

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

  royalty_lines.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.royalty_lines.belongsTo(db.royalty_reports, {
      as: 'royalty_report',
      foreignKey: {
        name: 'royalty_reportId',
      },
      constraints: false,
    });

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

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

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




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

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



  return royalty_lines;
};


