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

company_name: {
        type: DataTypes.TEXT,
      
      

      },

company_legal_name: {
        type: DataTypes.TEXT,
      
      

      },

company_website: {
        type: DataTypes.TEXT,
      
      

      },

company_size: {
        type: DataTypes.ENUM,
      
      

        values: [

"micro",


"small",


"medium",


"large",


"enterprise"

        ],

      },

verification_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"unverified",


"pending",


"verified",


"rejected"

        ],

      },

about: {
        type: DataTypes.TEXT,
      
      

      },

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

  job_companies.associate = (db) => {


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































    db.job_companies.hasMany(db.job_listings, {
      as: 'job_listings_company',
      foreignKey: {
          name: 'companyId',
      },
      constraints: false,
    });














//end loop



    db.job_companies.belongsTo(db.users, {
      as: 'owner',
      foreignKey: {
        name: 'ownerId',
      },
      constraints: false,
    });

    db.job_companies.belongsTo(db.addresses, {
      as: 'hq_address',
      foreignKey: {
        name: 'hq_addressId',
      },
      constraints: false,
    });

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



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


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

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



  return job_companies;
};


