'use strict';

const expect = require('chai').expect;
const sinon  = require('sinon');

const CommandInjector = require('./command-mock-utils').CommandInjector;
const getGlobals      = require('./command-mock-utils').getGlobals;

const Player = require('../../src/player').Player;
const Npc = require('../../src/npcs').Npc;
const Room = require('../../src/rooms').Room;
const Type = require('../../src/type').Type;
const Item = require('../../src/items').Item;
Type.config(Player, Npc, {}, {});

const socket = {
  write: sinon.stub()
}
const player = new Player(socket);

const getCmd = require('../../commands/get').command;
const globals = getGlobals();
const get = CommandInjector(getCmd, globals);

const [ rooms, items, players, npcs, Commands ] = globals;
players.addPlayer(player);

sinon.spy(player, 'warn');
sinon.spy(items, 'get');

describe('successfully getting something from a room', () => {

});

describe.only('failing to get stuff from a room', () => {
  const location = 2;
  const newRoom = new Room({ location });
  rooms.addRoom(newRoom);
  player.setLocation(location);

  it('should not let you get things during combat', () => {
    player.setInCombat({});

    get('thing', player);

    const call = player.warn.getCall(0);
    expect(call.args[0] === "You cannot do that while you're fighting.").to.be.true;
    expect(items.get.called).to.be.false;

    player.fleeFromCombat();
  });

  it('should not let you get an item that is not in your room', () => {

    get('potatos', player);

    const call = player.warn.getCall(1);
    expect(call.args[0] === 'The potatos could not be found here.').to.be.true;
  });

  it('should not let you get an item if it is infinitely heavy...', () => {
    const attributes = { weight: Infinity };
    const keywords = ['burrito'];
    const uuid = 'wat';
    const heavyItemConfig = { name: 'burrito', keywords, attributes, location, uuid };
    const heavyItem = new Item(heavyItemConfig);
    items.addItem(heavyItem); //TODO: Make this consistent. Room shouldn't need the uuid passed, should just get it.
    newRoom.addItem(heavyItem.getUuid());

    get('burrito', player);

    const call = player.warn.getCall(2);
    expect(call.args[0] === "You are not able to carry that.").to.be.true;
  });

  it('should not let you get an item if it is too heavy...', () => {
    const attributes = { weight: 200 };
    const keywords = ['taco'];
    const uuid = 'hokay';
    const heavyItemConfig = { name: 'taco', keywords, attributes, location, uuid };
    const heavyItem = new Item(heavyItemConfig);
    items.addItem(heavyItem); //TODO: Make this consistent. Room shouldn't need the uuid passed, should just get it.
    newRoom.addItem(heavyItem.getUuid());

    get('taco', player);

    const call = player.warn.getCall(3);
    console.log(call.args);
    expect(call.args[0] === "You are not able to carry that.").to.be.true;
  });
});

@@ -841,137 +841,8 @@
 );%0A%0A
-describe('successfully getting something from a room', () =%3E %7B%0A%0A%7D);%0A%0Adescribe.only('failing to get stuff from a room', () =%3E %7B%0A  
 cons
@@ -857,18 +857,16 @@
 on = 2;%0A
-  
 const ne
@@ -897,18 +897,16 @@
 ion %7D);%0A
-  
 rooms.ad
@@ -921,18 +921,16 @@
 wRoom);%0A
-  
 player.s
@@ -948,24 +948,78 @@
 location);%0A%0A
+describe('failing to get stuff from a room', () =%3E %7B%0A%0A
   it('should
@@ -1470,16 +1470,58 @@
 all(1);%0A
+    expect(items.get.called).to.be.false;%0A
     expe
@@ -2065,33 +2065,32 @@
 tem.getUuid());%0A
-%0A
     get('burrito
@@ -2143,16 +2143,67 @@
 all(2);%0A
+    console.log('infinite heavy:', call.args%5B0%5D);%0A%0A
     expe
@@ -2818,16 +2818,31 @@
 ole.log(
+'very heavy:', 
 call.arg
@@ -2842,16 +2842,19 @@
 all.args
+%5B0%5D
 );%0A    e
@@ -2929,12 +2929,467 @@
 ;%0A  %7D);%0A%7D);%0A
+%0Adescribe('successfully getting something from a room', () =%3E %7B%0A%0A  it('should be able to get a single item', () =%3E %7B%0A    const keywords = %5B'burger'%5D;%0A    const uuid = 'ham';%0A    const burgerConfig = %7B name: 'burger', keywords, uuid, location %7D%0A    const burger = new Item(burgerConfig);%0A    items.addItem(burger);%0A    newRoom.addItem(burger.getUuid());%0A%0A    get('burger', player);%0A%0A    expect(player.getInventory().includes(uuid)).to.be.true;%0A%0A  %7D);%0A%0A%7D);%0A

Add failing test for getting an item.