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

name: {
        type: DataTypes.TEXT,
      
      

      },

age: {
        type: DataTypes.INTEGER,
      
      

      },

profession: {
        type: DataTypes.ENUM,
      
      

        values: [

"shop_owner",


"farmer",


"fisher",


"teacher",


"baker",


"priest",


"student",


"tourist",


"harbor_worker",


"artisan",


"doctor",


"police",


"unemployed"

        ],

      },

personality: {
        type: DataTypes.ENUM,
      
      

        values: [

"friendly",


"shy",


"bold",


"serious",


"cheerful",


"grumpy",


"curious",


"romantic",


"ambitious",


"laid_back"

        ],

      },

bio: {
        type: DataTypes.TEXT,
      
      

      },

emotion_state: {
        type: DataTypes.ENUM,
      
      

        values: [

"happy",


"neutral",


"sad",


"angry",


"stressed",


"excited",


"tired"

        ],

      },

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

      },

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

  npcs.associate = (db) => {


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














    db.npcs.hasMany(db.family_memberships, {
      as: 'family_memberships_npc',
      foreignKey: {
          name: 'npcId',
      },
      constraints: false,
    });


    db.npcs.hasMany(db.npc_relationships, {
      as: 'npc_relationships_npc',
      foreignKey: {
          name: 'npcId',
      },
      constraints: false,
    });



    db.npcs.hasMany(db.dialogue_lines, {
      as: 'dialogue_lines_npc',
      foreignKey: {
          name: 'npcId',
      },
      constraints: false,
    });


    db.npcs.hasMany(db.quests, {
      as: 'quests_giver_npc',
      foreignKey: {
          name: 'giver_npcId',
      },
      constraints: false,
    });


    db.npcs.hasMany(db.quest_objectives, {
      as: 'quest_objectives_target_npc',
      foreignKey: {
          name: 'target_npcId',
      },
      constraints: false,
    });



    db.npcs.hasMany(db.employees, {
      as: 'employees_npc',
      foreignKey: {
          name: 'npcId',
      },
      constraints: false,
    });











    db.npcs.hasMany(db.sales_transactions, {
      as: 'sales_transactions_customer_npc',
      foreignKey: {
          name: 'customer_npcId',
      },
      constraints: false,
    });


















    db.npcs.hasMany(db.festival_attendance, {
      as: 'festival_attendance_npc',
      foreignKey: {
          name: 'npcId',
      },
      constraints: false,
    });




//end loop



    db.npcs.belongsTo(db.locations, {
      as: 'home_location',
      foreignKey: {
        name: 'home_locationId',
      },
      constraints: false,
    });

    db.npcs.belongsTo(db.locations, {
      as: 'work_location',
      foreignKey: {
        name: 'work_locationId',
      },
      constraints: false,
    });



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


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

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



  return npcs;
};


