﻿using System.IO;
using System.Threading;
using System.Threading.Tasks;

namespace TeamElem.IO
{
    public class LeaveOpenStream : Stream
    {
        private readonly Stream baseStream;

        public LeaveOpenStream(Stream baseStream)
        {
            this.baseStream = baseStream;
        }

        public override bool CanRead => baseStream.CanRead;

        public override bool CanSeek => baseStream.CanSeek;

        public override bool CanTimeout => baseStream.CanTimeout;

        public override bool CanWrite => baseStream.CanWrite;

        public override long Length => baseStream.Length;

        public override long Position
        {
            get { return baseStream.Position; }
            set { baseStream.Position = value; }
        }

        public override int ReadTimeout
        {
            get { return baseStream.ReadTimeout; }
            set { baseStream.ReadTimeout = value; }
        }

        public override int WriteTimeout
        {
            get { return baseStream.WriteTimeout; }
            set { baseStream.WriteTimeout = value; }
        }

        public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) => baseStream.CopyToAsync(destination, bufferSize, cancellationToken);

        public override void Flush() => baseStream.Flush();

        public override Task FlushAsync(CancellationToken cancellationToken) => baseStream.FlushAsync(cancellationToken);

        public override int Read(byte[] buffer, int offset, int count) => baseStream.Read(buffer, offset, count);

        public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => baseStream.ReadAsync(buffer, offset, count, cancellationToken);

        public override int ReadByte() => baseStream.ReadByte();

        public override long Seek(long offset, SeekOrigin origin) => baseStream.Seek(offset, origin);

        public override void SetLength(long value) => baseStream.SetLength(value);

        public override string ToString() => baseStream.ToString();

        public override void Write(byte[] buffer, int offset, int count) => baseStream.Write(buffer, offset, count);

        public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => baseStream.WriteAsync(buffer, offset, count, cancellationToken);

        public override void WriteByte(byte value) => baseStream.WriteByte(value);
    }
}
