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

start_time: {
        type: DataTypes.DATE,
      
      

      },

end_time: {
        type: DataTypes.DATE,
      
      

      },

hours: {
        type: DataTypes.DECIMAL,
      
      

      },

billable_rate: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"submitted",


"approved",


"billed"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  time_entries.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.time_entries.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.time_entries.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.time_entries.belongsTo(db.projects, {
      as: 'project',
      foreignKey: {
        name: 'projectId',
      },
      constraints: false,
    });

    db.time_entries.belongsTo(db.tasks, {
      as: 'task',
      foreignKey: {
        name: 'taskId',
      },
      constraints: false,
    });




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

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



  return time_entries;
};


