using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using skyscraper5.Dvb.DataBroadcasting.Biop;

namespace skyscraper5.Dvb.DataBroadcasting.SkyscraperVfs
{
    public abstract class VfsBase
    {
        protected VfsBase()
        {
            SkyscrpaerUiData = new Dictionary<string, object>();
        }

        public ObjectLocation ObjectLocation { get; set; }
        public VfsDirectory ParentDirectory;
        public string Name;
        public Dictionary<string, object> SkyscrpaerUiData { get; private set; }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            if (ParentDirectory != null)
            {
                sb.Append(ParentDirectory.ToString());
                sb.Append(Path.DirectorySeparatorChar);
            }

            sb.Append(Name);
            return sb.ToString();
        }

        public bool MatchObjectKey(byte[] r)
        {
            if (r == null)
                return false;
            if (ObjectLocation == null)
                return false;
            if (ObjectLocation.ObjectKey == null)
                return false;

            byte[] l = ObjectLocation.ObjectKey;
            if (l.Length != r.Length)
                return false;

            for (int i = 0; i < l.Length; i++)
            {
                if (l[i] != r[i])
                    return false;
            }

            return true;
        }

    }
}
