package com.swoosh.microblog.data

/**
 * Normalizes Ghost instance URLs to ensure proper format for Retrofit base URL.
 */
object UrlNormalizer {

    fun normalize(url: String): String {
        var normalized = url.trim()
        if (!normalized.startsWith("http://") && !normalized.startsWith("https://")) {
            normalized = "https://$normalized"
        }
        if (!normalized.endsWith("/")) {
            normalized = "$normalized/"
        }
        return normalized
    }
}

/**
 * Strips the URL scheme (http/https) and trailing slash for display purposes.
 * e.g., "https://example.com/" -> "example.com"
 */
fun String.toDisplayUrl(): String =
    removePrefix("https://").removePrefix("http://").removeSuffix("/")
