using ErsatzTV.Core;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Scheduling;

namespace ErsatzTV.Application.ProgramSchedules;

public record AddProgramScheduleItem(
    int ProgramScheduleId,
    StartType StartType,
    TimeSpan? StartTime,
    FixedStartTimeBehavior? FixedStartTimeBehavior,
    PlayoutMode PlayoutMode,
    CollectionType CollectionType,
    int? CollectionId,
    int? MultiCollectionId,
    int? SmartCollectionId,
    int? RerunCollectionId,
    int? MediaItemId,
    int? PlaylistId,
    string SearchTitle,
    string SearchQuery,
    PlaybackOrder PlaybackOrder,
    MarathonGroupBy MarathonGroupBy,
    bool MarathonShuffleGroups,
    bool MarathonShuffleItems,
    int? MarathonBatchSize,
    FillWithGroupMode FillWithGroupMode,
    MultipleMode MultipleMode,
    string MultipleCount,
    TimeSpan? PlayoutDuration,
    TailMode TailMode,
    int? DiscardToFillAttempts,
    string CustomTitle,
    GuideMode GuideMode,
    int? PreRollFillerId,
    int? MidRollFillerId,
    int? PostRollFillerId,
    int? TailFillerId,
    int? FallbackFillerId,
    List<int> WatermarkIds,
    List<int> GraphicsElementIds,
    string PreferredAudioLanguageCode,
    string PreferredAudioTitle,
    string PreferredSubtitleLanguageCode,
    ChannelSubtitleMode? SubtitleMode) : IRequest<Either<BaseError, ProgramScheduleItemViewModel>>,
    IProgramScheduleItemRequest
{
    public static AddProgramScheduleItem ForMediaItem(int scheduleId, CollectionType collectionType, int mediaItemId)
        => new(
            scheduleId,
            StartType.Dynamic,
            StartTime: null,
            FixedStartTimeBehavior: null,
            PlayoutMode.One,
            collectionType,
            CollectionId: null,
            MultiCollectionId: null,
            SmartCollectionId: null,
            RerunCollectionId: null,
            MediaItemId: mediaItemId,
            PlaylistId: null,
            SearchTitle: null,
            SearchQuery: null,
            PlaybackOrder.Shuffle,
            MarathonGroupBy.None,
            MarathonShuffleGroups: false,
            MarathonShuffleItems: false,
            MarathonBatchSize: null,
            FillWithGroupMode.None,
            MultipleMode.Count,
            MultipleCount: null,
            PlayoutDuration: null,
            TailMode.None,
            DiscardToFillAttempts: null,
            CustomTitle: null,
            GuideMode.Normal,
            PreRollFillerId: null,
            MidRollFillerId: null,
            PostRollFillerId: null,
            TailFillerId: null,
            FallbackFillerId: null,
            WatermarkIds: [],
            GraphicsElementIds: [],
            PreferredAudioLanguageCode: null,
            PreferredAudioTitle: null,
            PreferredSubtitleLanguageCode: null,
            SubtitleMode: null);
}
