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

title: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"final"

        ],

      },

deck_outline: {
        type: DataTypes.TEXT,
      
      

      },

generated_at: {
        type: DataTypes.DATE,
      
      

      },

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

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

    db.pitch_decks.belongsTo(db.ai_runs, {
      as: 'generated_by_run',
      foreignKey: {
        name: 'generated_by_runId',
      },
      constraints: false,
    });

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



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


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

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



  return pitch_decks;
};


