meta {
  name: POST branch select tier1
  type: http
  seq: 2
}

docs {
  NEO-48: tier-1 salvage branch pick. Run skill-progression grant (100+ XP for level 2) first if this denies level_too_low.
  On success, reasonCode is omitted from JSON (not null); test expects undefined.
}

post {
  url: {{baseUrl}}/game/players/dev-local-1/perk-state
  body: json
  auth: none
}

body:json {
  {
    "schemaVersion": 1,
    "skillId": "salvage",
    "tierIndex": 1,
    "branchId": "scrap_efficiency"
  }
}

tests {
  test("selects branch or denies with structured envelope", function () {
    expect(res.getStatus()).to.equal(200);
    const body = res.getBody();
    expect(body.schemaVersion).to.equal(1);
    expect(body.selected).to.be.a("boolean");
    expect(body.perkState).to.be.an("object");
    expect(body.perkState.schemaVersion).to.equal(1);
    expect(body.unlockedEvents).to.be.an("array");
    if (body.selected) {
      expect(body.reasonCode).to.be.undefined;
      const salvage = body.perkState.branchPicks.find((t) => t.skillId === "salvage");
      expect(salvage).to.be.an("object");
      const pick = salvage.picks.find((p) => p.tierIndex === 1);
      expect(pick.branchId).to.equal("scrap_efficiency");
    } else {
      expect(body.reasonCode).to.be.a("string");
    }
  });
}
