// Copyright 2026 printing-press-golden. Licensed under Apache-2.0. See LICENSE.
// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.

package cli

import (
	"encoding/json"
	"path/filepath"
	"testing"

	"mcp-cloudflare-pp-cli/internal/store"
)

func TestSyncSingleObject_PreservesLargeIntegerResourceIDs(t *testing.T) {
	dbPath := filepath.Join(t.TempDir(), "data.db")
	db, err := store.Open(dbPath)
	if err != nil {
		t.Fatalf("open: %v", err)
	}
	defer db.Close()

	if err := upsertSingleObject(db, "numeric_ids", json.RawMessage(`{"id": 55043301, "name": "large"}`)); err != nil {
		t.Fatalf("upsertSingleObject: %v", err)
	}

	var got string
	if err := db.DB().QueryRow(
		`SELECT id FROM resources WHERE resource_type = ?`,
		"numeric_ids",
	).Scan(&got); err != nil {
		t.Fatalf("query resource id: %v", err)
	}
	if got != "55043301" {
		t.Fatalf("resource id = %q, want %q", got, "55043301")
	}

	var literalMatches int
	if err := db.DB().QueryRow(
		`SELECT COUNT(*) FROM resources WHERE resource_type = ? AND id = '55043301'`,
		"numeric_ids",
	).Scan(&literalMatches); err != nil {
		t.Fatalf("count literal id matches: %v", err)
	}
	if literalMatches != 1 {
		t.Fatalf("literal id matches = %d, want 1", literalMatches)
	}
}
