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

message: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"sent",


"accepted",


"declined",


"expired",


"cancelled"

        ],

      },

sent_at: {
        type: DataTypes.DATE,
      
      

      },

responded_at: {
        type: DataTypes.DATE,
      
      

      },

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

  invites.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.invites.belongsTo(db.users, {
      as: 'sender',
      foreignKey: {
        name: 'senderId',
      },
      constraints: false,
    });

    db.invites.belongsTo(db.users, {
      as: 'receiver',
      foreignKey: {
        name: 'receiverId',
      },
      constraints: false,
    });

    db.invites.belongsTo(db.gigs, {
      as: 'gig',
      foreignKey: {
        name: 'gigId',
      },
      constraints: false,
    });




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

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



  return invites;
};


