using ImageMagick;
using PosterMaker.Interfaces.Services;
using PosterMaker.Models.Enums;

namespace PosterMaker.Services;

public class MovieLogoService : IMovieLogoService
{
    private static readonly string LogoDir = Path.Combine("Resources", "Logos");
    private static readonly string StudioDir = Path.Combine(LogoDir, "Studio");
    private static readonly string NetworkDir = Path.Combine(LogoDir, "Network");
    
    public byte[]? GetMovieLogo(MovieLogoEnum? logo)
    {
        if (logo == null) return null;
        var logoPath = Path.Combine(StudioDir, GetFileForLogo(logo));
        return File.ReadAllBytes(logoPath);;
    }
    
    public byte[]? GetNetworkLogo(NetworkLogoEnum? logo)
    {
        if (logo == null) return null;
        var logoPath = Path.Combine(NetworkDir, GetFileForNetworkLogo(logo));
        return File.ReadAllBytes(logoPath);
    }

    public Gravity GetLogoGravity(MovieLogoEnum? imagePropertiesLogo)
    {
        return imagePropertiesLogo switch
        {
            MovieLogoEnum.Disney => Gravity.North,
            MovieLogoEnum.DC => Gravity.North,
            MovieLogoEnum.SonyPicturesAnimation => Gravity.North,
            MovieLogoEnum.MarvelStudios => Gravity.North,
            MovieLogoEnum.A24 => Gravity.Northwest,
            MovieLogoEnum.Dreamworks => Gravity.North,
            MovieLogoEnum.DisneyPixar => Gravity.North,
            _ => throw new ArgumentOutOfRangeException(nameof(imagePropertiesLogo), imagePropertiesLogo, null)
        };
    }

    public MagickGeometry GetLogoGeometry(MovieLogoEnum? logoEnum)
    {
        var defaultGeometry = new MagickGeometry(200, 100);
        return logoEnum switch
        {
            MovieLogoEnum.Disney => defaultGeometry,
            MovieLogoEnum.DC => defaultGeometry,
            MovieLogoEnum.SonyPicturesAnimation => defaultGeometry,
            MovieLogoEnum.MarvelStudios => defaultGeometry,
            MovieLogoEnum.A24 => defaultGeometry,
            MovieLogoEnum.Dreamworks => defaultGeometry,
            MovieLogoEnum.DisneyPixar => new MagickGeometry(520, 100),
            _ => throw new ArgumentOutOfRangeException(nameof(logoEnum), logoEnum, null)
        };
    }

    public int GetNetworkLogoHeight(NetworkLogoEnum? logo)
    {
        return logo switch
        {
            NetworkLogoEnum.Hulu => 150,
            NetworkLogoEnum.Netflix => 200,
            NetworkLogoEnum.ParamountPlus => 200,
            _ => 150
        };
    }

    private string GetFileForLogo(MovieLogoEnum? logo)
    {
        return logo switch
        {
            MovieLogoEnum.Disney => "Disney.svg",
            MovieLogoEnum.DC => "DC.svg",
            MovieLogoEnum.SonyPicturesAnimation => "Sony_Pictures_Animation.svg",
            MovieLogoEnum.MarvelStudios => "Marvel_Studios.svg",
            MovieLogoEnum.A24 => "A24.svg",
            MovieLogoEnum.Dreamworks => "Dreamworks.svg",
            MovieLogoEnum.DisneyPixar => "DisneyPixar.svg",
            _ => throw new ArgumentOutOfRangeException(nameof(logo), logo, null)
        };
    }

    private string GetFileForNetworkLogo(NetworkLogoEnum? logo)
    {
        return logo switch
        {
            NetworkLogoEnum.Netflix => "Netflix.svg",
            NetworkLogoEnum.DisneyPlus => "DisneyPlus.svg",
            NetworkLogoEnum.AppleTv => "AppleTv.png",
            NetworkLogoEnum.Hbo => "HBO.svg",
            NetworkLogoEnum.Fxx => "FXX.svg",
            NetworkLogoEnum.Cbs => "CBS.svg",
            NetworkLogoEnum.Peacock => "Peacock.svg",
            NetworkLogoEnum.AmazonPrimeVideo => "AmazonPrimeVideo.png",
            NetworkLogoEnum.Nbc => "NBC.svg",
            NetworkLogoEnum.Amc => "AMC.svg",
            NetworkLogoEnum.Starz => "Starz.svg",
            NetworkLogoEnum.Hulu => "Hulu.svg",
            NetworkLogoEnum.Cw => "CW.svg",
            NetworkLogoEnum.ParamountPlus => "ParamountPlus.svg",
            NetworkLogoEnum.ComedyCentral => "ComedyCentral.svg",
            NetworkLogoEnum.Abc => "ABC.svg",
            NetworkLogoEnum.Bbc => "BBC.svg",
            NetworkLogoEnum.Usa => "USA.svg",
            NetworkLogoEnum.Tbs => "TBS.svg",
            NetworkLogoEnum.Fx => "FX.svg",
            NetworkLogoEnum.AdultSwim => "AdultSwim.svg",
            NetworkLogoEnum.Max => "Max.svg",
            NetworkLogoEnum.Mtv => "MTV.svg",
            NetworkLogoEnum.ChannelFour => "ChannelFour.png",
            _ => throw new ArgumentOutOfRangeException(nameof(logo), logo, null)
        };
    }
}