package api

import (
	"testing"

	"github.com/ponzischeme89/memby/server/internal/sonarr"
)

func TestIsSeasonFinale(t *testing.T) {
	episodes := []sonarr.Episode{
		{SeasonNumber: 2, EpisodeNumber: 1},
		{SeasonNumber: 2, EpisodeNumber: 8},
		{SeasonNumber: 2, EpisodeNumber: 10},
		{SeasonNumber: 3, EpisodeNumber: 1},
	}
	if !isSeasonFinale(2, 10, episodes) {
		t.Fatal("last numbered episode in the season should be a finale")
	}
	if isSeasonFinale(2, 8, episodes) {
		t.Fatal("an episode followed by another episode in its season is not a finale")
	}
	if isSeasonFinale(0, 10, episodes) {
		t.Fatal("specials must not be announced as season finales")
	}
}

func TestProviderIDIsCaseInsensitive(t *testing.T) {
	if got := providerID(map[string]string{"Tvdb": "123"}, "tvdb"); got != "123" {
		t.Fatalf("provider id = %q, want 123", got)
	}
}
