using ExtensiblePortfolioSite.SDK.Plugins;

using System;
using System.IO;

namespace ExtensiblePortfolioSite.SDK.Resources
{
    /// <summary>
    /// Local File Resource
    /// </summary>
    [ResourceContainer("file")]
    public sealed class LocalFile : IResource
    {
        /// <inheritdoc cref="IResource.PublicallyAccessible"/>
        public bool PublicallyAccessible => false;
        /// <inheritdoc cref="IResource.WebCompatible"/>
        public bool WebCompatible => false;
        /// <inheritdoc cref="IResource.URI"/>
        public Uri URI { get; }

        /// <summary>
        /// Local On System FilePath
        /// </summary>
        public string LocalFilePath { get; }

        /// <inheritdoc cref="LocalFile"/>
        /// <param name="FilePath"></param>
        public LocalFile(String FilePath) : this(new Uri($"file://{FilePath}")) { }

        /// <inheritdoc cref="LocalFile"/>
        /// <param name="FileUri"></param>
        public LocalFile(Uri FileUri)
        {
            this.LocalFilePath = FileUri.AbsolutePath;
            this.URI = FileUri;
        }



        /// <inheritdoc cref="IResource.OpenStream"/>
        public Stream OpenStream() => File.OpenRead(this.LocalFilePath);
    }
}
