---
source: tests/backends_swift_snapshot_test.rs
expression: "&file.content"
---
// Generated by alef. Do not edit by hand.
// swift-format-ignore-file

import Foundation
import RustBridge
/// A system-role chat message.
public struct SystemMessage: Codable, Sendable, Hashable {
    public let content: String
    public let name: String?
    public init(content: String, name: String? = nil) {
        self.content = content
        self.name = name
    }
    private enum CodingKeys: String, CodingKey {
        case content = "content"
        case name = "name"
    }
    public init(from decoder: any Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        self.content = try container.decodeIfPresent(String.self, forKey: .content) ?? ""
        self.name = try container.decodeIfPresent(String.self, forKey: .name) ?? nil
    }
}

// MARK: - Internal FFI conversions for SystemMessage
internal extension SystemMessage {
    init(_ rb: RustBridge.SystemMessageRef) throws {
        self.content = rb.content().toString()
        self.name = rb.name()?.toString()
    }

    func intoRust() throws -> RustBridge.SystemMessage {
        return RustBridge.SystemMessage(RustString(self.content), self.name.map(RustString.init))
    }
}

public typealias SystemMessageRef = RustBridge.SystemMessageRef

public typealias SystemMessageRefMut = RustBridge.SystemMessageRefMut

// MARK: - From-JSON Helpers
// Public helpers that decode JSON into first-class Swift types.
// First-class struct types (Codable) use JSONDecoder directly.
// Opaque RustBridge types forward to RustBridge.

public func systemMessageFromJson(_ json: String) throws -> SystemMessage {
    let data = json.data(using: .utf8) ?? Data()
    return try JSONDecoder().decode(SystemMessage.self, from: data)
}
// swift-bridge opaque type used across Task.detached boundaries — Rust type is Send + Sync.
extension RustBridge.SystemMessage: @unchecked Sendable {}
