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

default_retention_period: {
        type: DataTypes.ENUM,
      
      

        values: [

"30_days",


"90_days",


"180_days",


"1_year",


"3_years",


"7_years",


"indefinite"

        ],

      },

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

      },

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

      },

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

      },

date_format: {
        type: DataTypes.ENUM,
      
      

        values: [

"yyyy_mm_dd",


"mm_dd_yyyy",


"dd_mm_yyyy"

        ],

      },

branding_primary_color: {
        type: DataTypes.TEXT,
      
      

      },

notification_email_from_name: {
        type: DataTypes.TEXT,
      
      

      },

notification_email_from_address: {
        type: DataTypes.TEXT,
      
      

      },

slack_webhook_url: {
        type: DataTypes.TEXT,
      
      

      },

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

  organization_settings.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.organization_settings.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });



    db.organization_settings.hasMany(db.file, {
      as: 'branding_logo',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.organization_settings.getTableName(),
        belongsToColumn: 'branding_logo',
      },
    });


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

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



  return organization_settings;
};


