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

activity_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"running",


"cycling",


"swimming",


"rowing",


"walking",


"hiking",


"elliptical",


"jump_rope",


"sports",


"other"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

ended_at: {
        type: DataTypes.DATE,
      
      

      },

duration_minutes: {
        type: DataTypes.INTEGER,
      
      

      },

distance_km: {
        type: DataTypes.DECIMAL,
      
      

      },

avg_heart_rate: {
        type: DataTypes.DECIMAL,
      
      

      },

perceived_effort: {
        type: DataTypes.INTEGER,
      
      

      },

calories: {
        type: DataTypes.INTEGER,
      
      

      },

route_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  cardio_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.cardio_sessions.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });



    db.cardio_sessions.hasMany(db.file, {
      as: 'gps_route_file',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.cardio_sessions.getTableName(),
        belongsToColumn: 'gps_route_file',
      },
    });


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

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



  return cardio_sessions;
};


