package storage

import "testing"

func TestDeviceConfigStateRepoUpsertsAndGetsState(t *testing.T) {
    store := openTestStore(t)
    defer store.Close()

    repo := NewDeviceConfigStateRepo(store.DB())
    err := repo.Upsert(DeviceConfigStateRecord{
        DeviceID:          "edge-01",
        TemplateName:      "helmet",
        ProfileName:       "gate_a",
        OverlaysJSON:      `["night_relaxed"]`,
        ConfigID:          "cfg-001",
        ConfigVersion:     "20260427.1",
        LastAppliedTaskID: "task-1",
    })
    if err != nil {
        t.Fatalf("Upsert: %v", err)
    }

    item, err := repo.Get("edge-01")
    if err != nil {
        t.Fatalf("Get: %v", err)
    }
    if item == nil {
        t.Fatal("expected config state")
    }
    if item.ProfileName != "gate_a" || item.ConfigVersion != "20260427.1" || item.LastAppliedTaskID != "task-1" {
        t.Fatalf("unexpected state: %#v", item)
    }
}
