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

provider: {
        type: DataTypes.ENUM,
      
      

        values: [

"booking_com",


"expedia",


"airbnb",


"agoda",


"other"

        ],

      },

account_identifier: {
        type: DataTypes.TEXT,
      
      

      },

api_key_reference: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

      },

last_sync_at: {
        type: DataTypes.DATE,
      
      

      },

sync_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"ok",


"warning",


"error",


"disabled"

        ],

      },

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

  ota_connections.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.ota_connections.belongsTo(db.hotels, {
      as: 'hotel',
      foreignKey: {
        name: 'hotelId',
      },
      constraints: false,
    });

    db.ota_connections.belongsTo(db.sales_channels, {
      as: 'sales_channel',
      foreignKey: {
        name: 'sales_channelId',
      },
      constraints: false,
    });

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




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

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



  return ota_connections;
};


