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

share_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"public_link",


"private_link",


"qr"

        ],

      },

token: {
        type: DataTypes.TEXT,
      
      

      },

access_level: {
        type: DataTypes.ENUM,
      
      

        values: [

"view",


"upload",


"comment",


"download"

        ],

      },

expires_at: {
        type: DataTypes.DATE,
      
      

      },

max_uses: {
        type: DataTypes.INTEGER,
      
      

      },

uses_count: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

revoked_at: {
        type: DataTypes.DATE,
      
      

      },

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

  shares.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.shares.belongsTo(db.albums, {
      as: 'album',
      foreignKey: {
        name: 'albumId',
      },
      constraints: false,
    });

    db.shares.belongsTo(db.users, {
      as: 'created_by',
      foreignKey: {
        name: 'created_byId',
      },
      constraints: false,
    });

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




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

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



  return shares;
};


