package hetznerapi

import (
	"encoding/json"
	"testing"
)

// goldenPoolBox is the (redacted, non-secret) response captured from the Phase-0 probe of the live pool
// box 611714 (2026-07-17): GET /storage_boxes/{id}. The stats/capacity extension must decode it EXACTLY.
const goldenPoolBox = `{
  "storage_box": {
    "id": 611714,
    "username": "u629488",
    "name": "storage-box-pool-1",
    "status": "active",
    "server": "u629488.your-storagebox.de",
    "storage_box_type": { "id": 1333, "name": "bx11", "description": "BX11", "size": 1099511627776 },
    "stats": { "size": 2746220544, "size_data": 2746220544, "size_snapshots": 0 }
  }
}`

// TestStorageBox_DecodesProbeShape pins the type extension to the live API shape: capacity is the box
// TYPE's size (1 TiB), and stats carries the total/data/snapshot split, all in bytes.
func TestStorageBox_DecodesProbeShape(t *testing.T) {
	var out struct {
		StorageBox StorageBox `json:"storage_box"`
	}
	if err := json.Unmarshal([]byte(goldenPoolBox), &out); err != nil {
		t.Fatalf("decode golden pool-box: %v", err)
	}
	b := out.StorageBox
	if b.ID != 611714 || b.Name != "storage-box-pool-1" || b.Status != "active" {
		t.Fatalf("base fields wrong: %+v", b)
	}
	if b.StorageBoxType.Name != "bx11" || b.StorageBoxType.Size != 1099511627776 {
		t.Fatalf("capacity (storage_box_type.size) wrong: %+v", b.StorageBoxType)
	}
	if b.Stats.Size != 2746220544 || b.Stats.SizeData != 2746220544 || b.Stats.SizeSnapshots != 0 {
		t.Fatalf("stats wrong: %+v", b.Stats)
	}
	// Sanity: the split sums to the total (the invariant the live box holds).
	if b.Stats.SizeData+b.Stats.SizeSnapshots != b.Stats.Size {
		t.Fatalf("data+snapshots (%d) != total (%d)", b.Stats.SizeData+b.Stats.SizeSnapshots, b.Stats.Size)
	}
}
