import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { assert } from 'chai';
import computeCreatureComputation from '../../computeCreatureComputation.js';
import clean from '../../utility/cleanProp.testFn.js';

export default function(){
  const computation = buildComputationFromProps(testProperties);
  computeCreatureComputation(computation);
  const prop = id => computation.propsById[id];
  const scope = id => computation.scope[id].value;

  assert.equal(scope('weightEquipment'), 2);
  assert.equal(scope('valueEquipment'), 3);

  assert.equal(scope('itemsAttuned'), 1);

  assert.equal(prop('childContainerId').carriedWeight, 69);
  assert.equal(prop('childContainerId').contentsWeight, 69);

  assert.equal(scope('weightCarried'), 104);
  assert.equal(scope('valueCarried'), 129);

  assert.equal(scope('weightTotal'), 104);
  assert.equal(scope('valueTotal'), 129);
}

var testProperties = [
  clean({
    _id: 'equippedAttunedItemId',
    type: 'item',
    equipped: true,
    attuned: true,
    weight: 2,
    value: 3,
    ancestors: [{id: 'charId'}],
  }),
  clean({
    _id: 'containerId',
    type: 'container',
    carried: true,
    weight: 5,
    value: 7,
    ancestors: [{id: 'charId'}],
  }),
  clean({
    _id: 'childContainerId',
    type: 'container',
    carried: true,
    weight: 11,
    value: 13,
    ancestors: [{id: 'charId'}, {id: 'containerId'}],
  }),
  clean({
    _id: 'childItemId',
    type: 'item',
    weight: 17,
    value: 19,
    ancestors: [{id: 'charId'}, {id: 'containerId'}],
  }),
  clean({
    _id: 'grandchildItemId',
    type: 'item',
    weight: 23, // 69 total
    value: 29, // 87 total
    quantity: 3,
    ancestors: [{id: 'charId'}, {id: 'containerId'}, {id: 'childContainerId'}],
  }),
];
