package musicbrainz import ( "naviwatcher/internal/database" ) // FilterOptions holds per-artist type filtering preferences. type FilterOptions struct { IgnoreSingles bool IgnoreCompilations bool } // hasSliceType reports whether the slice contains any of the wanted values. func hasSliceType(types []string, wanted ...string) bool { for _, s := range types { for _, w := range wanted { if s == w { return true } } } return false } // ApplyTypeToggles filters releases based on the IgnoreSingles and IgnoreCompilations flags. // Implements canonical filtering logic: // IgnoreSingles filters: Type == "Single" OR Type == "EP" OR SecondaryTypes contains "Single" OR "EP" // IgnoreCompilations filters: Type == "Compilation" OR SecondaryTypes contains "Compilation" func ApplyTypeToggles(releases []database.ExternalRelease, opts FilterOptions) []database.ExternalRelease { var result []database.ExternalRelease for _, release := range releases { // Apply IgnoreSingles filtering: filter out if Type is Single/EP OR SecondaryTypes contains Single/EP if opts.IgnoreSingles { if release.Type == "Single" || release.Type == "EP" || hasSliceType(release.SecondaryTypes, "Single", "EP") { continue } } // Apply IgnoreCompilations filtering: filter out if Type is Compilation OR SecondaryTypes contains Compilation if opts.IgnoreCompilations { if release.Type == "Compilation" || hasSliceType(release.SecondaryTypes, "Compilation") { continue } } result = append(result, release) } return result } // ApplyTypeTogglesToReleaseGroups applies the same IgnoreSingles/IgnoreCompinators filtering logic // to a slice of ReleaseGroup objects. func ApplyTypeTogglesToReleaseGroups(groups []ReleaseGroup, opts FilterOptions) []ReleaseGroup { var result []ReleaseGroup for _, rg := range groups { // Apply IgnoreSingles filtering: filter out if Type is Single/EP OR SecondaryTypes contains Single/EP if opts.IgnoreSingles { if rg.Type == "Single" || rg.Type == "EP" || hasSliceType(rg.SecondaryTypes, "Single", "EP") { continue } } // Apply IgnoreCompilations filtering: filter out if Type is Compilation OR SecondaryTypes contains Compilation if opts.IgnoreCompilations { if rg.Type == "Compilation" || hasSliceType(rg.SecondaryTypes, "Compilation") { continue } } result = append(result, rg) } return result }