package store

import (
	"testing"
	"time"
)

func TestSnapshotKey_NoPrefix(t *testing.T) {
	cases := []struct {
		ts   time.Time
		want string
	}{
		{time.Date(2026, 4, 12, 9, 20, 0, 0, time.UTC), "snapshots/2026/04/12/0920.json"},
		{time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC), "snapshots/2026/01/01/0000.json"},
		{time.Date(2026, 12, 31, 23, 59, 0, 0, time.UTC), "snapshots/2026/12/31/2359.json"},
	}
	for _, tc := range cases {
		if got := snapshotKey("", tc.ts); got != tc.want {
			t.Errorf("ts %v: got %q want %q", tc.ts, got, tc.want)
		}
	}
}

func TestSnapshotKey_WithPrefix(t *testing.T) {
	ts := time.Date(2026, 4, 12, 9, 20, 0, 0, time.UTC)
	cases := []struct {
		prefix string
		want   string
	}{
		{"prod", "snapshots/prod/2026/04/12/0920.json"},
		{"staging", "snapshots/staging/2026/04/12/0920.json"},
	}
	for _, tc := range cases {
		if got := snapshotKey(tc.prefix, ts); got != tc.want {
			t.Errorf("prefix %q: got %q want %q", tc.prefix, got, tc.want)
		}
	}
}

func TestKeyPrefix(t *testing.T) {
	cases := []struct {
		prefix string
		want   string
	}{
		{"", "snapshots/"},
		{"prod", "snapshots/prod/"},
		{"staging", "snapshots/staging/"},
	}
	for _, tc := range cases {
		s := &S3Store{prefix: tc.prefix}
		if got := s.keyPrefix(); got != tc.want {
			t.Errorf("prefix %q: got %q want %q", tc.prefix, got, tc.want)
		}
	}
}
