package drive

import (
	"github.com/ultisuite/ulti-backend/internal/driveroot"
)

func pathRefFromParts(rootKind, rootID, path string) (driveroot.Ref, error) {
	kind, err := driveroot.ParseKind(rootKind)
	if err != nil {
		return driveroot.Ref{}, ErrInvalid
	}
	return driveroot.Ref{Kind: kind, RootID: rootID, Path: path}, nil
}

func pathRefFromMoveSource(req *moveRequest) (driveroot.Ref, error) {
	return pathRefFromParts(req.SourceRoot, req.SourceRootID, req.Source)
}

func pathRefFromMoveDestination(req *moveRequest) (driveroot.Ref, error) {
	return pathRefFromParts(req.DestinationRoot, req.DestinationRootID, req.Destination)
}

func pathRefFromCopySource(req *copyRequest) (driveroot.Ref, error) {
	return pathRefFromParts(req.SourceRoot, req.SourceRootID, req.Source)
}

func pathRefFromCopyDestination(req *copyRequest) (driveroot.Ref, error) {
	return pathRefFromParts(req.DestinationRoot, req.DestinationRootID, req.Destination)
}

func pathRefFromRename(req *renameRequest) (driveroot.Ref, error) {
	return pathRefFromParts(req.Root, req.RootID, req.Path)
}

func pathRefFromFavorite(req *favoriteRequest) (driveroot.Ref, error) {
	return pathRefFromParts(req.Root, req.RootID, req.Path)
}

func pathRefFromShare(req *createShareRequest) (driveroot.Ref, error) {
	return pathRefFromParts(req.Root, req.RootID, req.Path)
}

func usesAlternateRoot(ref driveroot.Ref) bool {
	return ref.Kind != driveroot.KindPersonal && ref.Kind != ""
}
