import Foundation

struct ShareLinkService: ShareLinkProviding {
    func shareURL(for card: BusinessCard) -> URL {
        card.shareURL
    }

    func smsURL(for card: BusinessCard) -> URL {
        let body = String.localized("ShareTextBody", card.displayName, card.shareURL.absoluteString)
        let query = body.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
        return URL(string: "sms:&body=\(query)") ?? card.shareURL
    }

    func emailURL(for card: BusinessCard) -> URL {
        let subject = String.localized("ShareEmailSubject", card.displayName)
        let body = String.localized("ShareEmailBody", card.displayName, card.shareURL.absoluteString)
        let subjectQuery = subject.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
        let bodyQuery = body.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
        return URL(string: "mailto:?subject=\(subjectQuery)&body=\(bodyQuery)") ?? card.shareURL
    }

    func whatsappURL(for card: BusinessCard) -> URL {
        let message = String.localized("ShareWhatsAppBody", card.displayName, card.shareURL.absoluteString)
        let query = message.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
        return URL(string: "https://wa.me/?text=\(query)") ?? card.shareURL
    }

    func linkedInURL(for card: BusinessCard) -> URL {
        let query = card.shareURL.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
        return URL(string: "https://www.linkedin.com/sharing/share-offsite/?url=\(query)") ?? card.shareURL
    }
}
