// secondary-interface.test-mojom.MojoProfile.swift is auto generated by mojom_bindings_generator.py, do not edit

// Copyright 2026 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This file is autogenerated by:
//     mojo/public/tools/bindings/generators/mojom_fuzzilli_generator.py
// For:
//     secondary-interface.test-mojom
//

private let mojoPrefix = "golden."

///
/// Interfaces
///
extension ILType {
    // Primary
    fileprivate static let jsGoldenPrimaryRemote: ILType = .object(
        ofGroup: "golden.PrimaryRemote",
        withProperties: ["$"],
        withMethods: [
            "sendObserver",
            "sendDelegateTwo",
            "getDelegateOne",
            "getObserverTwo",
            "syncGetObserverTwo",
        ])
    fileprivate static let jsGoldenPrimaryRemoteWrapper: ILType = .object(
        ofGroup: "golden.PrimaryRemoteWrapper",
        withMethods: ["close", "isBound", "associateAndPassReceiver"])
    fileprivate static let jsGoldenPrimaryPendingReceiver: ILType = .object(
        ofGroup: "golden.PrimaryPendingReceiver")

    // DelegateOne
    fileprivate static let jsGoldenDelegateOneRemote: ILType = .object(
        ofGroup: "golden.DelegateOneRemote",
        withProperties: ["$"],
        withMethods: [
            "method",
        ])
    fileprivate static let jsGoldenDelegateOneRemoteWrapper: ILType = .object(
        ofGroup: "golden.DelegateOneRemoteWrapper",
        withMethods: ["close", "isBound", "associateAndPassReceiver"])
    fileprivate static let jsGoldenDelegateOnePendingReceiver: ILType = .object(
        ofGroup: "golden.DelegateOnePendingReceiver")

    // DelegateTwo
    fileprivate static let jsGoldenDelegateTwoRemote: ILType = .object(
        ofGroup: "golden.DelegateTwoRemote",
        withProperties: ["$"],
        withMethods: [
        ])
    fileprivate static let jsGoldenDelegateTwoRemoteWrapper: ILType = .object(
        ofGroup: "golden.DelegateTwoRemoteWrapper",
        withMethods: ["close", "isBound", "associateAndPassReceiver"])
    fileprivate static let jsGoldenDelegateTwoPendingReceiver: ILType = .object(
        ofGroup: "golden.DelegateTwoPendingReceiver")

    // ObserverOne
    fileprivate static let jsGoldenObserverOneCallbackRouter: ILType = .object(
        ofGroup: "golden.ObserverOneCallbackRouter",
        withProperties: [
            "$",
            "sendDelegateTwo",
        ])
    fileprivate static let jsGoldenObserverOneCallbackRouterReceiverHelper: ILType = .object(
        ofGroup: "golden.ObserverOneCallbackRouterReceiverHelper",
        withMethods: ["associateAndPassRemote", "closeBindings"])
    fileprivate static let jsGoldenObserverOneRemote: ILType = .object(
        ofGroup: "golden.ObserverOneRemote",
        withProperties: ["$"])
    fileprivate static let jsGoldenObserverOneRemoteWrapper: ILType = .object(
        ofGroup: "golden.ObserverOneRemoteWrapper",
        withMethods: ["close", "isBound", "associateAndPassReceiver"])
    fileprivate static let jsGoldenObserverOnePendingReceiver: ILType = .object(
        ofGroup: "golden.ObserverOnePendingReceiver")
    fileprivate static let jsGoldenObserverOneSendDelegateTwoCallbackReceiver: ILType = .object(
        ofGroup: "GoldenObserverOneSendDelegateTwoCallbackReceiver",
        withMethods: ["addListener"])

    // ObserverTwo
    fileprivate static let jsGoldenObserverTwoCallbackRouter: ILType = .object(
        ofGroup: "golden.ObserverTwoCallbackRouter",
        withProperties: [
            "$",
        ])
    fileprivate static let jsGoldenObserverTwoCallbackRouterReceiverHelper: ILType = .object(
        ofGroup: "golden.ObserverTwoCallbackRouterReceiverHelper",
        withMethods: ["associateAndPassRemote", "closeBindings"])
    fileprivate static let jsGoldenObserverTwoRemote: ILType = .object(
        ofGroup: "golden.ObserverTwoRemote",
        withProperties: ["$"])
    fileprivate static let jsGoldenObserverTwoRemoteWrapper: ILType = .object(
        ofGroup: "golden.ObserverTwoRemoteWrapper",
        withMethods: ["close", "isBound", "associateAndPassReceiver"])
    fileprivate static let jsGoldenObserverTwoPendingReceiver: ILType = .object(
        ofGroup: "golden.ObserverTwoPendingReceiver")
}

extension ObjectGroup {
    // Primary
    fileprivate static let goldenPrimaryRemote = ObjectGroup(
        name: "golden.PrimaryRemote",
        instanceType: .jsGoldenPrimaryRemote,
        properties: ["$": .jsGoldenPrimaryRemoteWrapper],
        methods: [
            "sendObserver": [
                .plain(.boolean),
                .plain(.jsGoldenObserverOneRemote),
            ] => .jsPromise(resolvingTo: .jsGoldenPrimary_SendObserver_ResponseParams),
            "sendDelegateTwo": [
                .plain(.jsGoldenDelegateTwoPendingReceiver),
                .plain(.integer),
            ] => .undefined,
            "getDelegateOne": [
            ] => .jsPromise(resolvingTo: .jsGoldenPrimary_GetDelegateOne_ResponseParams),
            "getObserverTwo": [
                .plain(.float),
            ] => .jsPromise(resolvingTo: .jsGoldenPrimary_GetObserverTwo_ResponseParams),
            "syncGetObserverTwo": [
                .plain(.float),
            ] => .jsGoldenPrimary_SyncGetObserverTwo_ResponseParams,
        ]
    )

    fileprivate static let goldenPrimaryRemoteWrapper = ObjectGroup(
        name: "golden.PrimaryRemoteWrapper",
        instanceType: .jsGoldenPrimaryRemoteWrapper,
        properties: [:],
        methods: [
            "close": [] => .undefined,
            "isBound": [] => .boolean,
            "associateAndPassReceiver": [] => .jsGoldenPrimaryPendingReceiver,
        ]
    )

    fileprivate static let goldenPrimaryPendingReceiver = ObjectGroup(
        name: "golden.PrimaryPendingReceiver",
        instanceType: .jsGoldenPrimaryPendingReceiver,
        properties: [:],
        methods: [:]
    )

    // DelegateOne
    fileprivate static let goldenDelegateOneRemote = ObjectGroup(
        name: "golden.DelegateOneRemote",
        instanceType: .jsGoldenDelegateOneRemote,
        properties: ["$": .jsGoldenDelegateOneRemoteWrapper],
        methods: [
            "method": [
                .plain(.integer),
            ] => .undefined,
        ]
    )

    fileprivate static let goldenDelegateOneRemoteWrapper = ObjectGroup(
        name: "golden.DelegateOneRemoteWrapper",
        instanceType: .jsGoldenDelegateOneRemoteWrapper,
        properties: [:],
        methods: [
            "close": [] => .undefined,
            "isBound": [] => .boolean,
            "associateAndPassReceiver": [] => .jsGoldenDelegateOnePendingReceiver,
        ]
    )

    fileprivate static let goldenDelegateOnePendingReceiver = ObjectGroup(
        name: "golden.DelegateOnePendingReceiver",
        instanceType: .jsGoldenDelegateOnePendingReceiver,
        properties: [:],
        methods: [:]
    )

    // DelegateTwo
    fileprivate static let goldenDelegateTwoRemote = ObjectGroup(
        name: "golden.DelegateTwoRemote",
        instanceType: .jsGoldenDelegateTwoRemote,
        properties: ["$": .jsGoldenDelegateTwoRemoteWrapper],
        methods: [:]
    )

    fileprivate static let goldenDelegateTwoRemoteWrapper = ObjectGroup(
        name: "golden.DelegateTwoRemoteWrapper",
        instanceType: .jsGoldenDelegateTwoRemoteWrapper,
        properties: [:],
        methods: [
            "close": [] => .undefined,
            "isBound": [] => .boolean,
            "associateAndPassReceiver": [] => .jsGoldenDelegateTwoPendingReceiver,
        ]
    )

    fileprivate static let goldenDelegateTwoPendingReceiver = ObjectGroup(
        name: "golden.DelegateTwoPendingReceiver",
        instanceType: .jsGoldenDelegateTwoPendingReceiver,
        properties: [:],
        methods: [:]
    )

    // ObserverOne
    fileprivate static let goldenObserverOneCallbackRouter = ObjectGroup(
        name: "golden.ObserverOneCallbackRouter",
        instanceType: .jsGoldenObserverOneCallbackRouter,
        properties: [
            "$": .jsGoldenObserverOneCallbackRouterReceiverHelper,
            "sendDelegateTwo": .jsGoldenObserverOneSendDelegateTwoCallbackReceiver,
        ],
        methods: [:]
    )

    fileprivate static let goldenObserverOneCallbackRouterReceiverHelper = ObjectGroup(
        name: "golden.ObserverOneCallbackRouterReceiverHelper",
        instanceType: .jsGoldenObserverOneCallbackRouterReceiverHelper,
        properties: [:],
        methods: [
            "associateAndPassRemote": [] => .jsGoldenObserverOneRemote,
            "closeBindings": [] => .undefined,
        ]
    )

    fileprivate static let goldenObserverOneSendDelegateTwoCallbackReceiver = ObjectGroup(
        name: "GoldenObserverOneSendDelegateTwoCallbackReceiver",
        instanceType: .jsGoldenObserverOneSendDelegateTwoCallbackReceiver,
        properties: [:],
        methods: [
            "addListener": [
                .plain(
                    .function(
                        [
                            .either(.integer, .undefined),
                            .plain(.jsGoldenDelegateOneRemote),
                        ] => .undefined))
            ] => .integer,
        ])

    fileprivate static let goldenObserverOneRemote = ObjectGroup(
        name: "golden.ObserverOneRemote",
        instanceType: .jsGoldenObserverOneRemote,
        properties: ["$": .jsGoldenObserverOneRemoteWrapper],
        methods: [:]
    )

    fileprivate static let goldenObserverOneRemoteWrapper = ObjectGroup(
        name: "golden.ObserverOneRemoteWrapper",
        instanceType: .jsGoldenObserverOneRemoteWrapper,
        properties: [:],
        methods: [
            "close": [] => .undefined,
            "isBound": [] => .boolean,
            "associateAndPassReceiver": [] => .jsGoldenObserverOnePendingReceiver,
        ]
    )

    fileprivate static let goldenObserverOnePendingReceiver = ObjectGroup(
        name: "golden.ObserverOnePendingReceiver",
        instanceType: .jsGoldenObserverOnePendingReceiver,
        properties: [:],
        methods: [:]
    )

    // ObserverTwo
    fileprivate static let goldenObserverTwoCallbackRouter = ObjectGroup(
        name: "golden.ObserverTwoCallbackRouter",
        instanceType: .jsGoldenObserverTwoCallbackRouter,
        properties: [
            "$": .jsGoldenObserverTwoCallbackRouterReceiverHelper,
        ],
        methods: [:]
    )

    fileprivate static let goldenObserverTwoCallbackRouterReceiverHelper = ObjectGroup(
        name: "golden.ObserverTwoCallbackRouterReceiverHelper",
        instanceType: .jsGoldenObserverTwoCallbackRouterReceiverHelper,
        properties: [:],
        methods: [
            "associateAndPassRemote": [] => .jsGoldenObserverTwoRemote,
            "closeBindings": [] => .undefined,
        ]
    )

    fileprivate static let goldenObserverTwoRemote = ObjectGroup(
        name: "golden.ObserverTwoRemote",
        instanceType: .jsGoldenObserverTwoRemote,
        properties: ["$": .jsGoldenObserverTwoRemoteWrapper],
        methods: [:]
    )

    fileprivate static let goldenObserverTwoRemoteWrapper = ObjectGroup(
        name: "golden.ObserverTwoRemoteWrapper",
        instanceType: .jsGoldenObserverTwoRemoteWrapper,
        properties: [:],
        methods: [
            "close": [] => .undefined,
            "isBound": [] => .boolean,
            "associateAndPassReceiver": [] => .jsGoldenObserverTwoPendingReceiver,
        ]
    )

    fileprivate static let goldenObserverTwoPendingReceiver = ObjectGroup(
        name: "golden.ObserverTwoPendingReceiver",
        instanceType: .jsGoldenObserverTwoPendingReceiver,
        properties: [:],
        methods: [:]
    )
}

///
/// Structs
///
extension ILType {
    fileprivate static let jsGoldenObserverOne_SendDelegateTwo_ResponseParams: ILType = .object(
        ofGroup: "golden.ObserverOne_SendDelegateTwo_ResponseParams",
        withProperties: [
            "result",
        ])
    fileprivate static let jsGoldenPrimary_SendObserver_ResponseParams: ILType = .object(
        ofGroup: "golden.Primary_SendObserver_ResponseParams",
        withProperties: [
            "result",
        ])
    fileprivate static let jsGoldenPrimary_GetDelegateOne_ResponseParams: ILType = .object(
        ofGroup: "golden.Primary_GetDelegateOne_ResponseParams",
        withProperties: [
            "delegate",
        ])
    fileprivate static let jsGoldenPrimary_GetObserverTwo_ResponseParams: ILType = .object(
        ofGroup: "golden.Primary_GetObserverTwo_ResponseParams",
        withProperties: [
            "observer",
            "flag",
        ])
    fileprivate static let jsGoldenPrimary_SyncGetObserverTwo_ResponseParams: ILType = .object(
        ofGroup: "golden.Primary_SyncGetObserverTwo_ResponseParams",
        withProperties: [
            "observer",
            "flag",
        ])
}

extension ObjectGroup {
    fileprivate static let goldenObserverOneSendDelegateTwoResponseParams = ObjectGroup(
        name: "golden.ObserverOne_SendDelegateTwo_ResponseParams",
        instanceType: .jsGoldenObserverOne_SendDelegateTwo_ResponseParams,
        properties: [
            "result": .boolean,
        ],
        methods: [:]
    )
    fileprivate static let goldenPrimarySendObserverResponseParams = ObjectGroup(
        name: "golden.Primary_SendObserver_ResponseParams",
        instanceType: .jsGoldenPrimary_SendObserver_ResponseParams,
        properties: [
            "result": .string,
        ],
        methods: [:]
    )
    fileprivate static let goldenPrimaryGetDelegateOneResponseParams = ObjectGroup(
        name: "golden.Primary_GetDelegateOne_ResponseParams",
        instanceType: .jsGoldenPrimary_GetDelegateOne_ResponseParams,
        properties: [
            "delegate": .jsGoldenDelegateOneRemote,
        ],
        methods: [:]
    )
    fileprivate static let goldenPrimaryGetObserverTwoResponseParams = ObjectGroup(
        name: "golden.Primary_GetObserverTwo_ResponseParams",
        instanceType: .jsGoldenPrimary_GetObserverTwo_ResponseParams,
        properties: [
            "observer": .jsGoldenObserverTwoPendingReceiver,
            "flag": .boolean,
        ],
        methods: [:]
    )
    fileprivate static let goldenPrimarySyncGetObserverTwoResponseParams = ObjectGroup(
        name: "golden.Primary_SyncGetObserverTwo_ResponseParams",
        instanceType: .jsGoldenPrimary_SyncGetObserverTwo_ResponseParams,
        properties: [
            "observer": .jsGoldenObserverTwoPendingReceiver,
            "flag": .boolean,
        ],
        methods: [:]
    )
}

///
/// Generators
///
// TODO(crbug.com/500386713) Consider using mojoBuiltins or another list instead of regex
private func isTargetObject(type: ILType) -> Bool {
    guard type.Is(.object()), let group = type.group else { return false }
    return group.starts(with: mojoPrefix)
}

/// Mojo variant of the builtin `MethodCallGenerator` that operates only on
/// "Mojo" objects instead of all the objects in the JavaScript environment,
/// most of which are unrelated to the interface. This generator emits random
/// method calls, generating any arguments that are not available.
private let MojoMethodCallGenerator = CodeGenerator("MojoMethodCallGenerator") {
    b in
    // Pick a variable among all Mojo variables with methods
    var targetVar = b.findVariable {
        let type = b.type(of: $0)
        return isTargetObject(type: type) && !type.methods.isEmpty
    }

    // If we can't find a Mojo object in scope, create the Primary remote
    guard let obj = targetVar else {
        let getRemoteFunc = b.createNamedVariable(forBuiltin: "getOrCreatePrimaryRemote")
        b.callFunction(getRemoteFunc, withArgs: [])
        return
    }

    let methodName = b.type(of: obj).randomMethod()!
    let signatures = b.methodSignatures(of: methodName, on: obj)
    let signature = chooseUniform(from: signatures)
    let arguments = b.findOrGenerateArguments(forSignature: signature)
    b.callMethod(methodName, on: obj, withArgs: arguments, guard: false)
}

/// Mojo variant of the builtin `PropertyRetrievalGenerator` that operates only
/// on "Mojo" objects instead of all the objects in the JavaScript environment,
/// most of which are unrelated to the interface. This generator emits random
/// property retrievals.
private let MojoPropertyRetrievalGenerator = CodeGenerator(
    "MojoPropertyRetrievalGenerator"
) { b in
    let targetVar = b.findVariable { isTargetObject(type: b.type(of: $0)) }
    guard let obj = targetVar else { return }

    let propertyName =
        b.type(of: obj).randomProperty() ?? b.randomCustomPropertyName()
    b.getProperty(propertyName, of: obj)
}

/// Generates a call to add a callback to the goldenObserverOneCallbackRouter.
///
/// The callback has one parameter, specified with `.parameters(n: 1)`. `build(n: 5)`
/// then tells Fuzzilli to populate the callback body with five random expressions.
private let MojoGoldenObserverOneRouterListenerGenerator = CodeGenerator(
    "MojoGoldenObserverOneRouterListenerGenerator",
    inputs: .required(.jsGoldenObserverOneCallbackRouter)
) { b, router in
    guard
        let eventName = ILType.jsGoldenObserverOneCallbackRouter.properties
            .subtracting(["$"])
            .randomElement()
    else {
        return
    }

    let listenerHost = b.getProperty(eventName, of: router)
    let callback = b.buildPlainFunction(with: .parameters(n: 1)) { args in
        if probability(0.2) {
            b.buildIf(args[0]) {
                let wrapper = b.getProperty("$", of: args[0])
                b.callMethod("close", on: wrapper, withArgs: [])
            }
        }
        b.build(n: 5)
    }
    b.callMethod("addListener", on: listenerHost, withArgs: [callback])
}

private let mojoBuiltins: [String: ILType] = [
    /// Profiles declare this method, a wrapper method around `getRemote` that follows
    /// the Singleton pattern, in `codePrefix`. This method ensures: (1) `getRemote`
    /// is only called once, and (2) the remote is saved to a global variable so it
    /// can be closed at the end of the program.
    "getOrCreatePrimaryRemote": .function([] => .jsGoldenPrimaryRemote),
    "golden.ObserverOneCallbackRouter":
       .constructor([] => .jsGoldenObserverOneCallbackRouter),
    "golden.ObserverTwoCallbackRouter":
       .constructor([] => .jsGoldenObserverTwoCallbackRouter),
]

private let keepGenerators = [
    "IntegerGenerator", "StringGenerator", "TernaryOperationGenerator",
    "PlainFunctionGenerator", "AsyncFunctionGenerator", "AwaitGenerator",
    "SubroutineReturnGenerator", "TryCatchGenerator",
]

private let mojoDisabledGenerators: [String] = CodeGenerators.map { $0.name }
    .filter {
        !keepGenerators.contains($0)
    }

let mojoPrimaryProfile = Profile(
    processArgs: { _ in return [] },
    processArgsReference: nil,
    processEnv: [
        "ASAN_OPTIONS": "detect_odr_violation=0:abort_on_error=1", "DISPLAY": ":20",
    ],
    maxExecsBeforeRespawn: 1000,
    timeout: Timeout.interval(11000, 11000),
    codePrefix: """
        let globalRemote = null;
        function getOrCreatePrimaryRemote() {
            if (!globalRemote) {
                globalRemote = golden.Primary.getRemote();
            }
            return globalRemote;
        }
        """,
    codeSuffix: "if (globalRemote) {globalRemote.$.close()}",
    ecmaVersion: v8Profile.ecmaVersion,
    startupTests: [
        ("fuzzilli('FUZZILLI_PRINT', 'test')", .shouldSucceed),
        (
            """
            if (typeof golden == 'undefined' \
            || golden?.Primary === undefined) \
            throw 'Primary not found'
            """,
            .shouldSucceed
        ),
    ] + v8Profile.startupTests,
    additionalCodeGenerators: [
        (MojoMethodCallGenerator, 10000),
        (MojoPropertyRetrievalGenerator, 10000),
        (MojoGoldenObserverOneRouterListenerGenerator, 5000),
    ] + commonMojoCodeGenerators,
    additionalProgramTemplates: WeightedList([]),
    disabledCodeGenerators: mojoDisabledGenerators,
    disabledMutators: [
        "ExplorationMutator", "ProbingMutator", "PropertyAccessorMutator"
    ],
    additionalBuiltins: mojoBuiltins.merging(commonMojoBuiltins) { (existing, _) in existing },
    additionalObjectGroups: [
        .goldenPrimaryRemote,
        .goldenPrimaryRemoteWrapper,
        .goldenPrimaryPendingReceiver,
        .goldenDelegateOneRemote,
        .goldenDelegateOneRemoteWrapper,
        .goldenDelegateOnePendingReceiver,
        .goldenDelegateTwoRemote,
        .goldenDelegateTwoRemoteWrapper,
        .goldenDelegateTwoPendingReceiver,
        .goldenObserverOneCallbackRouter,
        .goldenObserverOneCallbackRouterReceiverHelper,
        .goldenObserverOneRemote,
        .goldenObserverOneRemoteWrapper,
        .goldenObserverOnePendingReceiver,
        .goldenObserverOneSendDelegateTwoCallbackReceiver,
        .goldenObserverTwoCallbackRouter,
        .goldenObserverTwoCallbackRouterReceiverHelper,
        .goldenObserverTwoRemote,
        .goldenObserverTwoRemoteWrapper,
        .goldenObserverTwoPendingReceiver,
        .goldenObserverOneSendDelegateTwoResponseParams,
        .goldenPrimarySendObserverResponseParams,
        .goldenPrimaryGetDelegateOneResponseParams,
        .goldenPrimaryGetObserverTwoResponseParams,
        .goldenPrimarySyncGetObserverTwoResponseParams,
    ] + commonMojoObjectGroups,
    additionalEnumerations: [
    ] + commonMojoEnumerations,
    additionalOptionsBags: [
    ] + commonMojoOptionsBags,
    optionalPostProcessor: nil
)