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

name_en: {
        type: DataTypes.TEXT,

      },

name_kh: {
        type: DataTypes.TEXT,

      },

earn_rate: {
        type: DataTypes.DECIMAL,

      },

date_of_birth: {
        type: DataTypes.DATE,

      },

phone_number: {
        type: DataTypes.TEXT,

      },

start_work_date: {
        type: DataTypes.DATE,

      },

born_place: {
        type: DataTypes.TEXT,

      },

document_type: {
        type: DataTypes.TEXT,

      },

document_number: {
        type: DataTypes.TEXT,

      },

emergency_number: {
        type: DataTypes.TEXT,

      },

current_place: {
        type: DataTypes.TEXT,

      },

sex: {
        type: DataTypes.ENUM,

        values: [

"M",

"F"

        ],

      },

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

  shareholders.associate = (db) => {

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

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

  return shareholders;
};

