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

cpf: {
        type: DataTypes.TEXT,
      
      

      },

birth_date: {
        type: DataTypes.DATE,
      
      

      },

marital_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"solteiro",


"casado",


"divorciado",


"viuvo",


"uniao_estavel"

        ],

      },

spouse_cpf: {
        type: DataTypes.TEXT,
      
      

      },

spouse_name: {
        type: DataTypes.TEXT,
      
      

      },

mother_name: {
        type: DataTypes.TEXT,
      
      

      },

cep: {
        type: DataTypes.TEXT,
      
      

      },

street: {
        type: DataTypes.TEXT,
      
      

      },

house_number: {
        type: DataTypes.TEXT,
      
      

      },

address_complement: {
        type: DataTypes.TEXT,
      
      

      },

neighborhood: {
        type: DataTypes.TEXT,
      
      

      },

city: {
        type: DataTypes.TEXT,
      
      

      },

state_uf: {
        type: DataTypes.TEXT,
      
      

      },

phone: {
        type: DataTypes.TEXT,
      
      

      },

occupation_text: {
        type: DataTypes.TEXT,
      
      

      },

occupation_code: {
        type: DataTypes.TEXT,
      
      

      },

cbo_code: {
        type: DataTypes.TEXT,
      
      

      },

main_source_cnpj: {
        type: DataTypes.TEXT,
      
      

      },

voter_title: {
        type: DataTypes.TEXT,
      
      

      },

voter_zone: {
        type: DataTypes.TEXT,
      
      

      },

voter_section: {
        type: DataTypes.TEXT,
      
      

      },

nit_pis_pasep: {
        type: DataTypes.TEXT,
      
      

      },

caepf_number: {
        type: DataTypes.TEXT,
      
      

      },

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

  user_profiles.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.user_profiles.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

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




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

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



  return user_profiles;
};


