package pinterest

import (
	"testing"

	"pinscrape-allgo/internal/config"
)

func testConfig() *config.Config {
	cfg := &config.Config{}
	cfg.ImageResult = 7
	cfg.SnippetMaxPageSize = 50
	return cfg
}

func TestSearchSizesSingleRequest(t *testing.T) {
	c := &Client{cfg: testConfig()}

	cases := []struct {
		name       string
		wantImages int
		wantDesc   int
		wantSize   int
	}{
		{"images only uses image target", 7, 0, 7},
		{"desc target widens to snippet max", 7, 10, 50},
		{"desc target alone", 0, 10, 50},
		{"explicit large image target preserved", 30, 0, 30},
		{"both zero falls back to image_result", 0, 0, 7},
	}
	for _, tc := range cases {
		got := c.pageSizeFor(tc.wantImages, tc.wantDesc)
		if got != tc.wantSize {
			t.Errorf("%s: pageSizeFor(%d,%d) = %d, want %d",
				tc.name, tc.wantImages, tc.wantDesc, got, tc.wantSize)
		}
	}
}
