using Pilz.UI.Symbols;
using Pilz.UI.Telerik.Extensions;
using Telerik.WinControls;

namespace Pilz.UI.Telerik.Symbols;

public abstract class RadSymbolFactory<TSymbols> : SymbolFactory<TSymbols>, IRadSymbolFactory<TSymbols>
{
    public virtual RadSvgImage GetSvgImage(TSymbols svgImage, Size size)
    {
        using var stream = GetImageRessourceStream(svgImage);
        var img = RadSvgImage.FromStream(stream);

        if (!size.IsEmpty)
            img.Size = size;

        return img;
    }

    public virtual RadSvgImage GetSvgImageColored(TSymbols svgImage, SymbolSize size, Color color)
    {
        return GetSvgImageColored(svgImage, ResolveCommonSize(size), color);
    }

    public virtual RadSvgImage GetSvgImageColored(TSymbols svgImage, Size size, Color color)
    {
        var img = GetSvgImage(svgImage, size);
        img.ApplyColor(color);
        return img;
    }

    public override Image GetImage(TSymbols svgImage, SymbolSize size)
    {
        return GetImage(svgImage, ResolveCommonSize(size));
    }

    public override Image GetImage(TSymbols svgImage, Size size)
    {
        return GetImageFromSvg(GetSvgImage(svgImage, size));
    }

    public RadSvgImage GetSvgImage(TSymbols svgImage, SymbolSize size)
    {
        return GetSvgImage(svgImage, ResolveCommonSize(size));
    }

    public virtual Image GetImageColored(TSymbols svgImage, SymbolSize size, Color color)
    {
        return GetImageColored(svgImage, ResolveCommonSize(size), color);
    }

    public virtual Image GetImageColored(TSymbols svgImage, Size size, Color color)
    {
        return GetImageFromSvg(GetSvgImageColored(svgImage, size, color));
    }

    public virtual Image GetImageFromSvg(RadSvgImage svg)
    {
        return svg.ToImage();
    }
}