using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Jellyfin;
using ErsatzTV.Core.Metadata;

namespace ErsatzTV.Core.Interfaces.Jellyfin;

public interface IJellyfinApiClient
{
    Task<Either<BaseError, JellyfinServerInformation>> GetServerInformation(string address, string authorizationHeader);
    Task<Either<BaseError, List<JellyfinLibrary>>> GetLibraries(string address, string authorizationHeader);

    // #484: the six enumerations that feed a reconciliation sweep accept an optional per-enumeration
    // counter -- the three library-level ones (movies, music videos, shows) AND the three nested ones
    // (seasons per show, episodes per season, both episode variants), which feed the per-parent sweeps
    // in MediaServerTelevisionLibraryScanner. The caller creates one instance per enumeration, scoped
    // to the parent it sweeps, and reads it only after that enumeration completes; passing null (the
    // default) opts out and costs existing callers nothing.
    IAsyncEnumerable<Tuple<JellyfinMovie, int>> GetMovieLibraryItems(
        string address,
        string authorizationHeader,
        JellyfinLibrary library,
        MediaServerProjectionFailureCounter projectionFailures = null);

    IAsyncEnumerable<Tuple<JellyfinMusicVideo, int>> GetMusicVideoLibraryItems(
        string address,
        string authorizationHeader,
        JellyfinLibrary library,
        MediaServerProjectionFailureCounter projectionFailures = null);

    IAsyncEnumerable<Tuple<JellyfinShow, int>> GetShowLibraryItemsWithoutPeople(
        string address,
        string authorizationHeader,
        JellyfinLibrary library,
        MediaServerProjectionFailureCounter projectionFailures = null);

    // #484: the nested per-show season and per-season episode enumerations feed their own sweeps
    // (FlagFileNotFoundSeasons / FlagFileNotFoundEpisodes), so they carry the same optional counter.
    IAsyncEnumerable<Tuple<JellyfinSeason, int>> GetSeasonLibraryItems(
        string address,
        string authorizationHeader,
        JellyfinLibrary library,
        string showId,
        MediaServerProjectionFailureCounter projectionFailures = null);

    IAsyncEnumerable<Tuple<JellyfinEpisode, int>> GetEpisodeLibraryItems(
        string address,
        string authorizationHeader,
        JellyfinLibrary library,
        string seasonId,
        MediaServerProjectionFailureCounter projectionFailures = null);

    IAsyncEnumerable<Tuple<JellyfinEpisode, int>> GetEpisodeLibraryItemsWithoutPeople(
        string address,
        string authorizationHeader,
        JellyfinLibrary library,
        string seasonId,
        MediaServerProjectionFailureCounter projectionFailures = null);

    IAsyncEnumerable<Tuple<JellyfinCollection, int>> GetCollectionLibraryItems(
        string address,
        string authorizationHeader,
        int mediaSourceId);

    IAsyncEnumerable<Tuple<MediaItem, int>> GetCollectionItems(
        string address,
        string authorizationHeader,
        int mediaSourceId,
        string collectionId);

    Task<Either<BaseError, MediaVersion>> GetPlaybackInfo(
        string address,
        string authorizationHeader,
        JellyfinLibrary library,
        string itemId);

    Task<Either<BaseError, Option<JellyfinShow>>> GetSingleShow(
        string address,
        string authorizationHeader,
        JellyfinLibrary library,
        string showId);

    Task<Either<BaseError, List<JellyfinShow>>> SearchShowsByTitle(
        string address,
        string authorizationHeader,
        JellyfinLibrary library,
        string showTitle);

    Task<Either<BaseError, Option<JellyfinEpisode>>> GetSingleEpisode(
        string address,
        string authorizationHeader,
        JellyfinLibrary library,
        string seasonId,
        string episodeId);

}
