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

output_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"ad_copy",


"creative_brief",


"analysis_report",


"compliance_report",


"ab_variants",


"strategy_plan",


"research_notes"

        ],

      },

output_title: {
        type: DataTypes.TEXT,
      
      

      },

output_content: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

exported_at: {
        type: DataTypes.DATE,
      
      

      },

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

  generation_outputs.associate = (db) => {


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






















    db.generation_outputs.hasMany(db.output_citations, {
      as: 'output_citations_generation_output',
      foreignKey: {
          name: 'generation_outputId',
      },
      constraints: false,
    });


    db.generation_outputs.hasMany(db.feedback_entries, {
      as: 'feedback_entries_generation_output',
      foreignKey: {
          name: 'generation_outputId',
      },
      constraints: false,
    });








//end loop



    db.generation_outputs.belongsTo(db.generation_runs, {
      as: 'generation_run',
      foreignKey: {
        name: 'generation_runId',
      },
      constraints: false,
    });




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

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



  return generation_outputs;
};


