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

evidence_claim: {
        type: DataTypes.TEXT,
      
      

      },

artifact_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"screenshot",


"export_csv",


"export_json",


"audit_log",


"ticket",


"attestation",


"configuration",


"policy_document",


"api_snapshot",


"other"

        ],

      },

required_fields: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

retention_period: {
        type: DataTypes.ENUM,
      
      

        values: [

"30_days",


"90_days",


"180_days",


"1_year",


"3_years",


"7_years",


"indefinite"

        ],

      },

evidence_strength: {
        type: DataTypes.ENUM,
      
      

        values: [

"weak",


"moderate",


"strong"

        ],

      },

collection_method: {
        type: DataTypes.ENUM,
      
      

        values: [

"manual",


"api",


"export",


"screenshot",


"ticket",


"log",


"attestation"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  evidence_models.associate = (db) => {


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












    db.evidence_models.hasMany(db.artifacts, {
      as: 'artifacts_evidence_model',
      foreignKey: {
          name: 'evidence_modelId',
      },
      constraints: false,
    });














//end loop



    db.evidence_models.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.evidence_models.belongsTo(db.identity_workflows, {
      as: 'workflow',
      foreignKey: {
        name: 'workflowId',
      },
      constraints: false,
    });

    db.evidence_models.belongsTo(db.control_requirements, {
      as: 'control_requirement',
      foreignKey: {
        name: 'control_requirementId',
      },
      constraints: false,
    });

    db.evidence_models.belongsTo(db.connected_systems, {
      as: 'source_system',
      foreignKey: {
        name: 'source_systemId',
      },
      constraints: false,
    });




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

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



  return evidence_models;
};


