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

name: {
        type: DataTypes.TEXT,
      
      

      },

project_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"expand_market",


"upgrade_harbor",


"improve_road",


"build_attraction",


"restore_building"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"planned",


"funding",


"in_progress",


"completed",


"paused",


"cancelled"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

budget_cost: {
        type: DataTypes.DECIMAL,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

  construction_projects.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.construction_projects.belongsTo(db.buildings, {
      as: 'building',
      foreignKey: {
        name: 'buildingId',
      },
      constraints: false,
    });




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

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



  return construction_projects;
};


