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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"planned",


"recording",


"completed",


"abandoned"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

ended_at: {
        type: DataTypes.DATE,
      
      

      },

input_channels: {
        type: DataTypes.INTEGER,
      
      

      },

sample_rate_hz: {
        type: DataTypes.INTEGER,
      
      

      },

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

  recording_sessions.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.recording_sessions.belongsTo(db.projects, {
      as: 'project',
      foreignKey: {
        name: 'projectId',
      },
      constraints: false,
    });

    db.recording_sessions.belongsTo(db.songs, {
      as: 'song',
      foreignKey: {
        name: 'songId',
      },
      constraints: false,
    });

    db.recording_sessions.belongsTo(db.users, {
      as: 'started_user',
      foreignKey: {
        name: 'started_userId',
      },
      constraints: false,
    });

    db.recording_sessions.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return recording_sessions;
};


