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

delivery_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"not_sent",


"queued",


"sent",


"processing",


"delivered",


"failed",


"takedown_sent",


"takedown_completed"

        ],

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

sent_at: {
        type: DataTypes.DATE,
      
      

      },

delivered_at: {
        type: DataTypes.DATE,
      
      

      },

platform_release_url: {
        type: DataTypes.TEXT,
      
      

      },

external_reference: {
        type: DataTypes.TEXT,
      
      

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

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

  release_deliveries.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.release_deliveries.belongsTo(db.releases, {
      as: 'release',
      foreignKey: {
        name: 'releaseId',
      },
      constraints: false,
    });

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

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




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

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



  return release_deliveries;
};


