package main

import (
	"log/slog"

	"git.sr.ht/~ashkeel/strimertul/log"
	"git.sr.ht/~ashkeel/strimertul/twitch"
)

type ProblemID string

const (
	ProblemIDTwitchNoApp    = "twitch:app_missing"
	ProblemIDEventSubNoAuth = "twitch:eventsub_no_auth"
	ProblemIDEventSubScope  = "twitch:eventsub_scope"
)

type Problem struct {
	ID      ProblemID `json:"id"`
	Details any       `json:"details"`
}

func (a *App) GetProblems() (problems []Problem) {
	problems = []Problem{}
	if a.twitchManager != nil {
		client := a.twitchManager.Client()
		if client != nil {
			// Check if the app needs to be authorized again
			scopesMatch, err := twitch.CheckScopes(client.DB)
			if err != nil {
				slog.Warn("Could not check scopes for problems", log.Error(err))
			} else {
				if !scopesMatch {
					problems = append(problems, Problem{
						ID:      ProblemIDEventSubScope,
						Details: nil,
					})
				}
			}
		}
	}
	return
}
