package storage

import (
    "path/filepath"
    "testing"
)

func TestModelsRepo_SaveAndList(t *testing.T) {
    store, err := OpenSQLite(filepath.Join(t.TempDir(), "app.db"))
    if err != nil {
        t.Fatalf("OpenSQLite: %v", err)
    }
    defer store.Close()

    repo := NewModelsRepo(store.DB())
    err = repo.Save(StandardModelRecord{
        Name:        "face_det_scrfd_500m_640",
        FileName:    "face_det_scrfd_500m_640_rk3588.rknn",
        Version:     "v1.0.0",
        SHA256:      "abc123",
        SizeBytes:   1024,
        ModelType:   "face_det",
        Description: "人脸检测模型",
    })
    if err != nil {
        t.Fatalf("Save: %v", err)
    }

    items, err := repo.List()
    if err != nil {
        t.Fatalf("List: %v", err)
    }
    if len(items) != 1 || items[0].Version != "v1.0.0" {
        t.Fatalf("unexpected models: %#v", items)
    }
}
