using System.IO;
using System.Linq;

namespace KattekerCreator.Types
{
    public struct PathFragments
    {
        private readonly string[] _fragments;

        public PathFragments(string path)
        {
            _fragments = path.Split(Path.DirectorySeparatorChar);
        }

        public int FragmentLength => _fragments.Length;

        public override bool Equals(object obj) => string.Equals(ToString(), obj?.ToString());

        public override int GetHashCode() => _fragments != null ? _fragments.GetHashCode() : 0;

        public override string ToString() => string.Join(Path.DirectorySeparatorChar.ToString(), _fragments.Take(_fragments.Length - 1));
    }
}