import std/paths
import ../src/[careers, factions, game, items, shipmodules, shipscargo, types]
import unittest2

suite "Unit tests for shipscargo module":

  checkpoint "Loading the game data."
  loadData("bin/data/game.dat".Path)
  loadItems("bin/data/items.dat".Path)
  loadCareers("bin/data/careers.dat".Path)
  loadFactions("bin/data/factions.dat".Path)
  loadModules("bin/data/shipmodules.dat".Path)

  playerShip.modules = @[]
  playerShip.modules.add(y = initModuleData(mType = cargoRoom, protoIndex = 7,
      durability = 100, maxDurability = 100, name = "Cargo", weight = 1))
  playerShip.cargo = @[]
  playerShip.cargo.add(y = initInventoryData(protoIndex = 1, amount = 100,
      durability = 100))
  playerShip.cargo.add(y = initInventoryData(protoIndex = 3, amount = 200,
      durability = 100))
  const attribute = initMobAttributeRecord(level = 3, experience = 0)
  playerShip.crew = @[]
  playerShip.crew.add(y = initMemberData(morale = [1: 50.Natural, 2: 0.Natural],
      homeBase = 1, faction = "POLEIS", orders = [0.Natural, 0, 0, 1, 1, 1, 2, 1,
      1, 1, 0, 0], order = talk, loyalty = 100, skills = @[initSkillInfo(index = 4,
      level = 4, experience = 0)], attributes = @[attribute, attribute, attribute, attribute], health = 100))

  test "Remove an item from the player's ship cargo":
    updateCargo(playerShip, 1, -1, quality = normal, craftBonus = none,
        craftMalus = none)
    check:
      playerShip.cargo[0].amount == 99

  test "Add an item to the player's ship cargo":
    updateCargo(playerShip, 1, 1, quality = normal, craftBonus = none,
        craftMalus = none)
    check:
      playerShip.cargo[0].amount == 100
    updateCargo(playerShip, 40, -1, quality = normal, craftBonus = none,
        craftMalus = none)

  test "Checking a free space in the player's ship cargo.":
    check:
      freeCargo(1) > freeCargo(0)

  test "Getting amount of an item in the player's ship cargo.":
    check:
      getItemAmount("Fuel") == 100

  test "Getting amount of items in the player's ship cargo.":
    check:
      getItemsAmount("Drinks") == 200
