using System.IO;

namespace Kav
{
    internal class Resources
    {
        public static byte[] DeferredPBR_AmbientLightEffect
        {
            get
            {
                if (ambientLightEffect == null)
                {
                    ambientLightEffect = GetResource("DeferredPBR_AmbientLightEffect.fxb");
                }
                return ambientLightEffect;
            }
        }
        public static byte[] DeferredPBR_PointLightEffect
        {
            get
            {
                if (pointLightEffect == null)
                {
                    pointLightEffect = GetResource("DeferredPBR_PointLightEffect.fxb");
                }
                return pointLightEffect;
            }
        }

        public static byte[] DeferredPBR_DirectionalLightEffect
        {
            get
            {
                if (directionalLightEffect == null)
                {
                    directionalLightEffect = GetResource("DeferredPBR_DirectionalLightEffect.fxb");
                }
                return directionalLightEffect;
            }
        }

        public static byte[] DeferredPBR_GBufferEffect
        {
            get
            {
                if (gBufferEffect == null)
                {
                    gBufferEffect = GetResource("DeferredPBR_GBufferEffect.fxb");
                }
                return gBufferEffect;
            }
        }

        public static byte[] ToneMapEffect
        {
            get
            {
                if (toneMapEffect == null)
                {
                    toneMapEffect = GetResource("ToneMapEffect.fxb");
                }
                return toneMapEffect;
            }
        }

        public static byte[] Deferred_ToonEffect
        {
            get
            {
                if (deferredToonEffect == null)
                {
                    deferredToonEffect = GetResource("Deferred_ToonEffect.fxb");
                }
                return deferredToonEffect;
            }
        }

        public static byte[] DeferredPBREffect
        {
            get
            {
                if (deferredPBREffect == null)
                {
                    deferredPBREffect = GetResource("DeferredPBREffect.fxb");
                }
                return deferredPBREffect;
            }
        }

        public static byte[] PBREffect
        {
            get
            {
                if (pbrEffect == null)
                {
                    pbrEffect = GetResource("PBREffect.fxb");
                }
                return pbrEffect;
            }
        }

        public static byte[] SimpleDepthEffect
        {
            get
            {
                if (simpleDepthEffect == null)
                {
                    simpleDepthEffect = GetResource("SimpleDepthEffect.fxb");
                }
                return simpleDepthEffect;
            }
        }

        public static byte[] SimpleDepthEffectInstanced
        {
            get
            {
                if (simpleDepthEffectInstanced == null)
                {
                    simpleDepthEffectInstanced = GetResource("SimpleDepthEffectInstanced.fxb");
                }
                return simpleDepthEffectInstanced;
            }
        }

        public static byte[] LinearDepthEffect
        {
            get
            {
                if (linearDepthEffect == null)
                {
                    linearDepthEffect = GetResource("LinearDepthEffect.fxb");
                }
                return linearDepthEffect;
            }
        }

        public static byte[] LinearDepthEffectInstanced
        {
            get
            {
                if (linearDepthEffectInstanced == null)
                {
                    linearDepthEffectInstanced = GetResource("LinearDepthEffectInstanced.fxb");
                }
                return linearDepthEffectInstanced;
            }
        }

        public static byte[] SkyboxEffect
        {
            get
            {
                if (skyboxEffect == null)
                {
                    skyboxEffect = GetResource("SkyboxEffect.fxb");
                }
                return skyboxEffect;
            }
        }

        public static byte[] DiffuseLitSpriteEffect
        {
            get
            {
                if (diffuseLitSpriteEffect == null)
                {
                    diffuseLitSpriteEffect = GetResource("DiffuseLitSpriteEffect.fxb");
                }
                return diffuseLitSpriteEffect;
            }
        }

        public static byte[] PaletteCrushEffect
        {
            get
            {
                if (paletteCrushEffect == null)
                {
                    paletteCrushEffect = GetResource("PaletteCrushEffect.fxb");
                }
                return paletteCrushEffect;
            }
        }

        public static byte[] UnitCubeModel
        {
            get
            {
                if (unitCubeModel == null)
                {
                    unitCubeModel = GetResource("UnitCube.glb");
                }
                return unitCubeModel;
            }
        }

        public static byte[] UnitSphereModel
        {
            get
            {
                if (unitSphereModel == null)
                {
                    unitSphereModel = GetResource("UnitSphere.glb");
                }
                return unitSphereModel;
            }
        }

        private static byte[] ambientLightEffect;
        private static byte[] pointLightEffect;
        private static byte[] directionalLightEffect;
        private static byte[] gBufferEffect;
        private static byte[] toneMapEffect;
        private static byte[] deferredToonEffect;
        private static byte[] deferredPBREffect;
        private static byte[] pbrEffect;
        private static byte[] simpleDepthEffect;
        private static byte[] simpleDepthEffectInstanced;
        private static byte[] linearDepthEffect;
        private static byte[] linearDepthEffectInstanced;
        private static byte[] skyboxEffect;
        private static byte[] diffuseLitSpriteEffect;
        private static byte[] paletteCrushEffect;

        private static byte[] unitCubeModel;
        private static byte[] unitSphereModel;

        private static byte[] GetResource(string name)
        {
            Stream stream = typeof(Resources).Assembly.GetManifestResourceStream(
                "Kav.Resources." + name
            );
            using (MemoryStream ms = new MemoryStream())
            {
                stream.CopyTo(ms);
                return ms.ToArray();
            }
        }
    }
}