package path

import (
	"path/filepath"
	"strings"
)

var _ Path = Relative("")

// Relative is a relative path, i.e. a path that does neither start with a slash, nor with
// a schema.
type Relative string

// String return the representation of the path as a string.
func (r Relative) String() string {
	return string(r)
}

// Relative fullfills the the Path interface and returns the relative part of the path, which is always itself.
func (r Relative) Relative() Relative {
	return r
}

// Join returns a new relative path by joining the old one with
// the given parts. within the parts, directories must end with a slash /
func (r Relative) Join(parts ...string) Relative {
	var all []string
	all = append(all, r.String())
	all = append(all, parts...)
	return Relative(join(all...))
}

// ToSystem represents the relative path in the most common way for the current system
// Slashes at the end will be chopped off
func (r Relative) ToSystem() string {
	str := r.String()
	str = strings.TrimRight(str, "/")
	return filepath.FromSlash(str)
}