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; }

        private string FilePath;

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



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