package utils

import (
	"fmt"
	"net/url"
	"strings"
)

func ExtractCompanyName(urlStr string) (string, error) {
	parsedURL, err := url.Parse(urlStr)

	if err != nil {
		return "", fmt.Errorf("failed to parse URL: %w", err)
	}

	path := parsedURL.Path
	segments := strings.Split(strings.Trim(path, "/"), "/")

	if len(segments) > 0 && segments[0] != "" {
		return segments[0], nil
	}

	return "", fmt.Errorf("no path segments found")
}
