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

task_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"intake",


"collect_evidence",


"payer_call",


"submit",


"follow_up",


"review_ai_extraction",


"draft_appeal",


"clinical_review",


"export_packet",


"other"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"open",


"in_progress",


"blocked",


"done",


"canceled"

        ],

      },

priority: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"normal",


"high",


"urgent"

        ],

      },

due_at: {
        type: DataTypes.DATE,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.tasks.belongsTo(db.locations, {
      as: 'location',
      foreignKey: {
        name: 'locationId',
      },
      constraints: false,
    });

    db.tasks.belongsTo(db.authorization_cases, {
      as: 'authorization_case',
      foreignKey: {
        name: 'authorization_caseId',
      },
      constraints: false,
    });

    db.tasks.belongsTo(db.users, {
      as: 'assigned_to_user',
      foreignKey: {
        name: 'assigned_to_userId',
      },
      constraints: false,
    });




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

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



  return tasks;
};


