package backend

import (
	"log"
	"os"
	"strings"
)

func GetCharacters() []string {
	musicPath := os.Getenv("MUSIC_PATH")
	charactersPath := musicPath + "characters/"
	files, err := os.ReadDir(charactersPath)
	if err != nil {
		log.Fatal(err)
	}

	var characters []string
	for _, file := range files {
		if isImage(file) {
			characters = append(characters, file.Name())
		}
	}
	return characters
}

func GetCharacter(character string) string {
	musicPath := os.Getenv("MUSIC_PATH")
	charactersPath := musicPath + "characters/"
	return charactersPath + character
}

func isImage(entry os.DirEntry) bool {
	return !entry.IsDir() && (strings.HasSuffix(entry.Name(), ".jpg") || strings.HasSuffix(entry.Name(), ".png"))
}

