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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"completed",


"failed"

        ],

      },

source_language: {
        type: DataTypes.TEXT,
      
      

      },

target_language: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

confidence_avg: {
        type: DataTypes.DECIMAL,
      
      

      },

transcript_text: {
        type: DataTypes.TEXT,
      
      

      },

summary_text: {
        type: DataTypes.TEXT,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

finished_at: {
        type: DataTypes.DATE,
      
      

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

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

  transcription_jobs.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.transcription_jobs.belongsTo(db.users, {
      as: 'requested_by',
      foreignKey: {
        name: 'requested_byId',
      },
      constraints: false,
    });

    db.transcription_jobs.belongsTo(db.matters, {
      as: 'matter',
      foreignKey: {
        name: 'matterId',
      },
      constraints: false,
    });

    db.transcription_jobs.belongsTo(db.files, {
      as: 'media_file',
      foreignKey: {
        name: 'media_fileId',
      },
      constraints: false,
    });

    db.transcription_jobs.belongsTo(db.files, {
      as: 'export_file',
      foreignKey: {
        name: 'export_fileId',
      },
      constraints: false,
    });




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

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



  return transcription_jobs;
};


