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

code: {
        type: DataTypes.TEXT,

      },

name_en: {
        type: DataTypes.TEXT,

      },

name_kh: {
        type: DataTypes.TEXT,

      },

date_of_birth: {
        type: DataTypes.DATE,

      },

phone_number: {
        type: DataTypes.TEXT,

      },

is_new: {
        type: DataTypes.BOOLEAN,

        allowNull: false,
        defaultValue: false,

      },

document_number: {
        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,
    },
  );

  clients.associate = (db) => {

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

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

  return clients;
};

