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

type: {
        type: DataTypes.ENUM,
      
      

        values: [

"POD_SIGNED",


"CMR_SIGNED",


"DELIVERY_NOTE",


"DAMAGE_REPORT",


"OTHER"

        ],

      },

provider: {
        type: DataTypes.ENUM,
      
      

        values: [

"S3",


"AZURE_BLOB",


"GCS",


"LOCAL"

        ],

      },

file_key: {
        type: DataTypes.TEXT,
      
      

      },

file_name: {
        type: DataTypes.TEXT,
      
      

      },

mime_type: {
        type: DataTypes.TEXT,
      
      

      },

size_bytes: {
        type: DataTypes.INTEGER,
      
      

      },

file_url: {
        type: DataTypes.TEXT,
      
      

      },

checksum_sha256: {
        type: DataTypes.TEXT,
      
      

      },

uploaded_at: {
        type: DataTypes.DATE,
      
      

      },

uploaded_by: {
        type: DataTypes.TEXT,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  pod_files.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.pod_files.belongsTo(db.companies, {
      as: 'company',
      foreignKey: {
        name: 'companyId',
      },
      constraints: false,
    });

    db.pod_files.belongsTo(db.load_stops, {
      as: 'stop',
      foreignKey: {
        name: 'stopId',
      },
      constraints: false,
    });




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

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



  return pod_files;
};


