package main

import (
	"fmt"
	"strings"
	"testing"
)

func TestGetRandomStyleList(t *testing.T) {
	numStyles := 4
	styles := getRandomStyleList(numStyles)
	fmt.Println(styles)
	if len(styles) != numStyles {
		t.Errorf("Expected %d styles, got %d", numStyles, len(styles))
	}
	styleSet := make(map[string]bool)
	for _, s := range styles {
		if styleSet[s] {
			t.Errorf("Duplicate style found: %s", s)
		}
		styleSet[s] = true
		found := false
		for _, valid := range songStyles {
			if s == valid {
				found = true
				break
			}
		}
		if !found {
			t.Errorf("Style %s not in songStyles list", s)
		}
	}
}

func TestGeneratePrompt(t *testing.T) {
	r := RadioState{
		styles: [numVoteStyles]string{"Loud", "Instrumental", "Groovy", "Chill"},
		votes:  [numVoteStyles]int{3, 2, 5, 0},
	}
	prompt, _ := r.GeneratePrompt()
	fmt.Println(prompt)
	if !containsAll(prompt, []string{"loud", "instrumental", "groovy", "chill"}) {
		t.Errorf("Prompt missing expected styles: %s", prompt)
	}
	if !containsAny(prompt, []string{"early morning", "afternoon", "evening", "night", "late night"}) {
		t.Errorf("Prompt missing expected time of day: %s", prompt)
	}
	if !containsAny(prompt, []string{"january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"}) {
		t.Errorf("Prompt missing expected month: %s", prompt)
	}
	if !containsAny(prompt, []string{"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"}) {
		t.Errorf("Prompt missing expected weekday: %s", prompt)
	}
}

func containsAll(s string, subs []string) bool {
	for _, sub := range subs {
		if !containsIgnoreCase(s, sub) {
			return false
		}
	}
	return true
}

func containsAny(s string, subs []string) bool {
	for _, sub := range subs {
		if containsIgnoreCase(s, sub) {
			return true
		}
	}
	return false
}

func containsIgnoreCase(s, sub string) bool {
	return strings.Contains(strings.ToLower(s), strings.ToLower(sub))
}
