// Generated by alef. Do not edit by hand.
// swift-format-ignore-file
// This file contains convenience overloads for plugin registration matching the alef e2e generator's call shapes.

import Foundation
import RustBridge

// MARK: - Path/UTF-8 helper used by the String overloads of extractBytes(Sync).

/// Treat the input as a filesystem path first (resolved against the test
/// fixtures directory if relative); fall back to the raw UTF-8 bytes if no
/// such file exists. The alef e2e generator emits fixture paths into
/// `extract_bytes` calls, but third-party callers may still want to pass
/// inline string content.
public func _loadBytesFromPathOrUtf8(_ pathOrContent: String) throws -> [UInt8] {
    let fm = FileManager.default
    var roots: [String] = [
        fm.currentDirectoryPath,
    ]
    if let envRoot = ProcessInfo.processInfo.environment["ALEF_TEST_DOCUMENTS_DIR"] {
        roots.append(envRoot)
    }
    var walker = URL(fileURLWithPath: fm.currentDirectoryPath)
    for _ in 0..<16 {
        roots.append(walker.appendingPathComponent("test_documents").path)
        roots.append(walker.appendingPathComponent("fixtures").path)
        let parent = walker.deletingLastPathComponent()
        if parent.path == walker.path { break }
        walker = parent
    }
    let candidates = [pathOrContent] + roots.map { ($0 as NSString).appendingPathComponent(pathOrContent) }
    for path in candidates {
        if fm.fileExists(atPath: path), let data = try? Data(contentsOf: URL(fileURLWithPath: path)) {
            return [UInt8](data)
        }
    }
    return [UInt8](pathOrContent.utf8)
}

// MARK: - Unregister name: label overloads

{% for trait in traits %}
public func unregister{{ trait.pascal_name }}(name: String) throws {
    try RustBridge.unregister{{ trait.pascal_name }}(name)
}

{% endfor %}
// MARK: - Bridge → Box register overloads

{% for trait in traits %}
public func register{{ trait.pascal_name }}(_ bridge: Swift{{ trait.pascal_name }}Bridge) throws {
    try register{{ trait.pascal_name }}(Swift{{ trait.pascal_name }}Box(_{{ trait.pascal_name }}BridgeAdapter(bridge: bridge)))
}

{% endfor %}
// MARK: - Internal stub adapters
//
// Each adapter conforms to the full plugin protocol expected by the
// `Swift<Plugin>Box` wrapper and delegates only the methods the bridge
// exposes. The remaining methods use safe defaults: register/initialize/
// shutdown are no-ops, processing entrypoints throw, capability queries
// report false/empty.
//
// Adapter stub names (returned by name() method):
{% for trait in traits -%}
// - _{{ trait.pascal_name }}BridgeAdapter → "swift-bridge-{{ trait.snake_name }}-stub"
{% endfor %}
//
// These names are used by e2e test cleanup to unregister stubs after each test.

private struct _BridgeStubError: Error, CustomStringConvertible {
    let description: String
}

{% for trait in traits %}
private final class _{{ trait.pascal_name }}BridgeAdapter: {{ trait.pascal_name }} {
    private let bridge: any Swift{{ trait.pascal_name }}Bridge
    init(bridge: any Swift{{ trait.pascal_name }}Bridge) { self.bridge = bridge }

    {% include trait.adapter_template %}
}

{% endfor %}
