
using Modules.Library.Domain.Entities.MediaContent.CommonProperties;

namespace Modules.Library.Domain.Entities.MediaContent.Items.Anime;

public abstract class AnimeItemSingle : AnimeItem
{
    protected readonly AnimeSeason? _season;
    public TimeSpan? Duration { get; private set; }
    public AnimeItemSingleDurationType DurationType { get; private set; }

    private protected AnimeItemSingle(AnimeTitle title, AnimeSeason? season) : base(title)
    {
        _season = season;
    }

    private protected AnimeItemSingle(AnimeTitle title, AnimeSeason? season, TimeSpan? duration) : base(title)
    {
        _season = season;
        SetDuration(duration);
    }

    internal AnimeItemSingle(AnimeTitle title, AnimeSeason? season, IEnumerable<NameItem> names, TimeSpan? duration) :
        base(title, names)
    {
        _season = season;
        SetDuration(duration);
    }

    public void SetDuration(TimeSpan? value)
    {
        Duration = value;
        DurationType = GetDurationType(Duration);
    }

    private static AnimeItemSingleDurationType GetDurationType(TimeSpan? value)
    {
        if (value >= TimeSpan.FromMinutes(18) && value <= TimeSpan.FromMinutes(45))
        {
            return AnimeItemSingleDurationType.Series;
        }
        if (value >= TimeSpan.FromHours(1) && value <= TimeSpan.FromHours(2))
        {
            return AnimeItemSingleDurationType.FullLength;
        }
        return AnimeItemSingleDurationType.Special;
    }

    protected override void StructureAction(Action action)
    {
        action.Invoke();
        _season?.CheckIfCompleted();
        _title.CheckIfCompleted();
    }

}

public enum AnimeItemSingleDurationType
{
    Series,
    FullLength,
    Special,
}