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

kms_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"internal",


"aws_kms",


"gcp_kms",


"azure_key_vault",


"customer_hsm"

        ],

      },

name: {
        type: DataTypes.TEXT,
      
      

      },

key_uri: {
        type: DataTypes.TEXT,
      
      

      },

kms_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"disabled",


"error"

        ],

      },

last_rotated_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

  kms_configs.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.kms_configs.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

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




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

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



  return kms_configs;
};


