//
//  ReuseTrace.swift
//  OpenSwiftUICore
//
//  Audited for 6.0.87
//  Status: WIP

package import OpenAttributeGraphShims

package struct ReuseTrace {
    package static func register(graph: Graph) {
        recorder = Recorder(graph: graph)
    }
    
    @inline(__always)
    package static var isEnabled: Bool { recorder != nil }
    
    package static var recorder: ReuseTrace.Recorder?
    
    @inline(__always)
    package static func traceReuseFailure(_ name: UnsafePointer<CChar>) {
        // TODO
        // guard let recorder else { return }
        // OAGGraphAddTraceEvent
        // recorder.graph.addTraceEvent(name)
    }

    @inline(__always)
    package static func traceReuseInternalFailure() {
        traceReuseFailure("resuse_internal")
    }

    @inline(__always)
    package static func traceReuseViewInputsDifferentFailure() {
        traceReuseFailure("reuse_inputsDifferent")
    }

    @inline(__always)
    package static func traceReuseSkippedNotIdle(_ subgraph: Subgraph) {
        // TODO
    }

    @inline(__always)
    package static func traceReuseItemUnplaced(_ subgraph: Subgraph) {
        // TODO
    }

    @inline(__always)
    package static func traceCacheItemRecycled(_ subgraph: Subgraph) {
        // TODO
    }

    @inline(__always)
    package static func traceReuseCacheItemPlaced(_ subgraph: Subgraph) {
        // TODO
    }

    @inline(__always)
    package static func traceReuseCacheItemFailure(_ subgraph: Subgraph) {
        // TODO
    }

    @inline(__always)
    package static func traceReuseCacheItemAdded(_ itemReuseIdentifier: Int, _ subgraph: Subgraph) {
        // TODO
    }

    @inline(__always)
    package static func traceMismatchedReuseIDFailure(_ itemReuseIdentifier: Int, _ subgraph: Subgraph) {
        // TODO
    }

    @inline(__always)
    package static func traceReuseIdentifier(_ itemReuseIdentifier: Int) {
        // TODO
    }

    @inline(__always)
    package static func traceReuseTypeComparisonFailure(_ baseType: (any Any.Type)?, _ candidateType: (any Any.Type)?) {
        // TODO
    }

    @inline(__always)
    package static func traceReuseUnaryElementExpectedFailure(_ elementType: any Any.Type) {
        traceReuseFailure("reuse_unaryElement")
    }

    @inline(__always)
    package static func traceReuseInvalidSubgraphFailure(_ typeFoundInvalid: any Any.Type) {
        // TODO
    }

    @inline(__always)
    package static func traceReuseIncompatibleListsFailure(_ baseList: any Any.Type, _ candidateList: any Any.Type) {
        // TODO
    }

    @inline(__always)
    package static func traceReuseBodyMismatchedFailure() {
        // TODO
    }

    @inline(__always)
    package static func traceNeverMadeReusableFailure(_ valueType: (any Any.Type)?) {
        // TODO
    }

    @inline(__always)
    package static func traceReusePreventedFailure(_ preventingType: any Any.Type) {
        // TODO
    }
    
    final package class Recorder {
        var graph: Graph
        var frameActive: Bool = false

        @inline(__always)
        init(graph: Graph) {
            self.graph = graph
        }
    }
}
