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

name: {
        type: DataTypes.TEXT,
      
      

      },

start_at: {
        type: DataTypes.DATE,
      
      

      },

end_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"planned",


"active",


"completed"

        ],

      },

planned_velocity: {
        type: DataTypes.DECIMAL,
      
      

      },

actual_velocity: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  sprints.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity


























    db.sprints.hasMany(db.sprint_items, {
      as: 'sprint_items_sprint',
      foreignKey: {
          name: 'sprintId',
      },
      constraints: false,
    });






//end loop



    db.sprints.belongsTo(db.teams, {
      as: 'team',
      foreignKey: {
        name: 'teamId',
      },
      constraints: false,
    });

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




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

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



  return sprints;
};


