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

name: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

default_duration_weeks: {
        type: DataTypes.INTEGER,
      
      

      },

default_budget: {
        type: DataTypes.DECIMAL,
      
      

      },

billing_model: {
        type: DataTypes.ENUM,
      
      

        values: [

"fixed_price",


"time_material",


"recurring"

        ],

      },

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

      },

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

  project_templates.associate = (db) => {


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

















    db.project_templates.hasMany(db.projects, {
      as: 'projects_template',
      foreignKey: {
          name: 'templateId',
      },
      constraints: false,
    });






























//end loop



    db.project_templates.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.project_templates.belongsTo(db.service_lines, {
      as: 'service_line',
      foreignKey: {
        name: 'service_lineId',
      },
      constraints: false,
    });

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




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

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



  return project_templates;
};


