import APIClient
import SwiftUI
import Utilities

/// Required conformance for `ShareSheet` support.
public protocol Shareable: Equatable {
    typealias Platform = ShareableTarget.Platform

    // Sheet Config
    static var sheetTitle: String { get }
    var shareActions: Set<ShareableTarget> { get }
    var supportsVideoRendering: Bool { get }

    // UI
    associatedtype Preview: View
    @ViewBuilder @MainActor var preview: Preview { get }

    // Share Data
    var title: String { get }
    var shareURL: URL { get }
    var shareText: String? { get }

    // Overrides `shareURL` when not `nil`.
    func getTemporaryAttributedShareURL(source: HooksFeedSource?) async throws -> ShareAttribution?
    func register(shareAttribution: ShareAttribution, for: Platform?) async throws
}

public extension Shareable {
    // Default to `false`.
    internal var supportsVideoRendering: Bool {
        false
    }

    // Default to `nil`. Concrete types can optionally override this
    func getTemporaryAttributedShareURL(source _: HooksFeedSource?) async throws -> ShareAttribution? {
        return nil
    }

    // Default to no-op. Concrete types can optionally override this
    func registerAttributedShareURL(for _: Platform?) async throws {}
}
