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

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

      },

terms_accepted_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

privacy_policy_accepted_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

marketing_opt_in_at: {
        type: DataTypes.DATE,
      
      

      },

consent_source: {
        type: DataTypes.ENUM,
      
      

        values: [

"web_guest_checkout",


"account_settings",


"admin_recorded"

        ],

      },

consent_version: {
        type: DataTypes.TEXT,
      
      

      },

ip_address: {
        type: DataTypes.TEXT,
      
      

      },

user_agent: {
        type: DataTypes.TEXT,
      
      

      },

lawful_basis: {
        type: DataTypes.ENUM,
      
      

        values: [

"contract",


"consent",


"legitimate_interest",


"legal_obligation"

        ],

      },

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

  gdpr_consents.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity

















    db.gdpr_consents.hasMany(db.guests, {
      as: 'guests_gdpr_consent',
      foreignKey: {
          name: 'gdpr_consentId',
      },
      constraints: false,
    });














//end loop






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

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



  return gdpr_consents;
};


