// basic-nullable.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:
//     basic-nullable.test-mojom
//

private let mojoPrefix = "golden."

///
/// Interfaces
///
extension ILType {
    // Primary
    fileprivate static let jsGoldenPrimaryRemote: ILType = .object(
        ofGroup: "golden.PrimaryRemote",
        withProperties: ["$"],
        withMethods: [
            "setStruct",
            "getArrayValue",
            "getMapValue",
            "sendObserver",
            "syncGetArrayValue",
            "syncGetMapValue",
        ])
    fileprivate static let jsGoldenPrimaryRemoteWrapper: ILType = .object(
        ofGroup: "golden.PrimaryRemoteWrapper",
        withMethods: ["close", "isBound", "associateAndPassReceiver"])
    fileprivate static let jsGoldenPrimaryPendingReceiver: ILType = .object(
        ofGroup: "golden.PrimaryPendingReceiver")

    // Observer
    fileprivate static let jsGoldenObserverCallbackRouter: ILType = .object(
        ofGroup: "golden.ObserverCallbackRouter",
        withProperties: [
            "$",
            "sendDelegate",
        ])
    fileprivate static let jsGoldenObserverCallbackRouterReceiverHelper: ILType = .object(
        ofGroup: "golden.ObserverCallbackRouterReceiverHelper",
        withMethods: ["associateAndPassRemote", "closeBindings"])
    fileprivate static let jsGoldenObserverRemote: ILType = .object(
        ofGroup: "golden.ObserverRemote",
        withProperties: ["$"])
    fileprivate static let jsGoldenObserverRemoteWrapper: ILType = .object(
        ofGroup: "golden.ObserverRemoteWrapper",
        withMethods: ["close", "isBound", "associateAndPassReceiver"])
    fileprivate static let jsGoldenObserverPendingReceiver: ILType = .object(
        ofGroup: "golden.ObserverPendingReceiver")
    fileprivate static let jsGoldenObserverSendDelegateCallbackReceiver: ILType = .object(
        ofGroup: "GoldenObserverSendDelegateCallbackReceiver",
        withMethods: ["addListener"])
}

extension ObjectGroup {
    // Primary
    fileprivate static let goldenPrimaryRemote = ObjectGroup(
        name: "golden.PrimaryRemote",
        instanceType: .jsGoldenPrimaryRemote,
        properties: ["$": .jsGoldenPrimaryRemoteWrapper],
        methods: [
            "setStruct": [
                .either(.jsGoldenSimpleStruct, .undefined),
            ] => .undefined,
            "getArrayValue": [
                .plain(.jsFloatArray),
                .plain(.integer),
            ] => .jsPromise(resolvingTo: .jsGoldenPrimary_GetArrayValue_ResponseParams),
            "getMapValue": [
                .plain(.jsString_IntegerMap),
                .plain(.string),
            ] => .jsPromise(resolvingTo: .jsGoldenPrimary_GetMapValue_ResponseParams),
            "sendObserver": [
                .either(.jsGoldenObserverRemote, .undefined),
            ] => .undefined,
            "syncGetArrayValue": [
                .plain(.jsFloatArray),
                .plain(.integer),
            ] => .jsGoldenPrimary_SyncGetArrayValue_ResponseParams,
            "syncGetMapValue": [
                .plain(.jsString_IntegerMap),
                .plain(.string),
            ] => .jsPromise(resolvingTo: .jsGoldenPrimary_SyncGetMapValue_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: [:]
    )

    // Observer
    fileprivate static let goldenObserverCallbackRouter = ObjectGroup(
        name: "golden.ObserverCallbackRouter",
        instanceType: .jsGoldenObserverCallbackRouter,
        properties: [
            "$": .jsGoldenObserverCallbackRouterReceiverHelper,
            "sendDelegate": .jsGoldenObserverSendDelegateCallbackReceiver,
        ],
        methods: [:]
    )

    fileprivate static let goldenObserverCallbackRouterReceiverHelper = ObjectGroup(
        name: "golden.ObserverCallbackRouterReceiverHelper",
        instanceType: .jsGoldenObserverCallbackRouterReceiverHelper,
        properties: [:],
        methods: [
            "associateAndPassRemote": [] => .jsGoldenObserverRemote,
            "closeBindings": [] => .undefined,
        ]
    )

    fileprivate static let goldenObserverSendDelegateCallbackReceiver = ObjectGroup(
        name: "GoldenObserverSendDelegateCallbackReceiver",
        instanceType: .jsGoldenObserverSendDelegateCallbackReceiver,
        properties: [:],
        methods: [
            "addListener": [
                .plain(
                    .function(
                        [
                            .plain(.integer),
                            .either(.boolean, .undefined),
                        ] => .undefined))
            ] => .integer,
        ])

    fileprivate static let goldenObserverRemote = ObjectGroup(
        name: "golden.ObserverRemote",
        instanceType: .jsGoldenObserverRemote,
        properties: ["$": .jsGoldenObserverRemoteWrapper],
        methods: [:]
    )

    fileprivate static let goldenObserverRemoteWrapper = ObjectGroup(
        name: "golden.ObserverRemoteWrapper",
        instanceType: .jsGoldenObserverRemoteWrapper,
        properties: [:],
        methods: [
            "close": [] => .undefined,
            "isBound": [] => .boolean,
            "associateAndPassReceiver": [] => .jsGoldenObserverPendingReceiver,
        ]
    )

    fileprivate static let goldenObserverPendingReceiver = ObjectGroup(
        name: "golden.ObserverPendingReceiver",
        instanceType: .jsGoldenObserverPendingReceiver,
        properties: [:],
        methods: [:]
    )
}

///
/// Structs
///
extension ILType {
    fileprivate static let jsGoldenSimpleStruct: ILType = .object(
        ofGroup: "golden.SimpleStruct",
        withProperties: [
            "field",
            "optionalField",
            "nestedStruct",
        ])
    fileprivate static let jsGoldenSimpleStructConstructor: ILType = .constructor([
        .plain(.string),
        .either(.string, .undefined),
        .either(.jsGoldenToken, .undefined),
    ] => .jsGoldenSimpleStruct)
    fileprivate static let jsGoldenToken: ILType = .object(
        ofGroup: "golden.Token",
        withProperties: [
        ])
    fileprivate static let jsGoldenTokenConstructor: ILType = .constructor([
    ] => .jsGoldenToken)
    fileprivate static let jsGoldenPrimary_GetArrayValue_ResponseParams: ILType = .object(
        ofGroup: "golden.Primary_GetArrayValue_ResponseParams",
        withProperties: [
            "result",
        ])
    fileprivate static let jsGoldenPrimary_GetMapValue_ResponseParams: ILType = .object(
        ofGroup: "golden.Primary_GetMapValue_ResponseParams",
        withProperties: [
            "result",
        ])
    fileprivate static let jsGoldenPrimary_SyncGetArrayValue_ResponseParams: ILType = .object(
        ofGroup: "golden.Primary_SyncGetArrayValue_ResponseParams",
        withProperties: [
            "result",
        ])
    fileprivate static let jsGoldenPrimary_SyncGetMapValue_ResponseParams: ILType = .object(
        ofGroup: "golden.Primary_SyncGetMapValue_ResponseParams",
        withProperties: [
            "result",
        ])
}

extension ObjectGroup {
    fileprivate static let goldenSimpleStruct = ObjectGroup(
        name: "golden.SimpleStruct",
        instanceType: .jsGoldenSimpleStruct,
        properties: [
            "field": .string,
            "optionalField": .string,
            "nestedStruct": .jsGoldenToken,
        ],
        methods: [:]
    )
    fileprivate static let goldenToken = ObjectGroup(
        name: "golden.Token",
        instanceType: .jsGoldenToken,
        properties: [:],
        methods: [:]
    )
    fileprivate static let goldenPrimaryGetArrayValueResponseParams = ObjectGroup(
        name: "golden.Primary_GetArrayValue_ResponseParams",
        instanceType: .jsGoldenPrimary_GetArrayValue_ResponseParams,
        properties: [
            "result": .float,
        ],
        methods: [:]
    )
    fileprivate static let goldenPrimaryGetMapValueResponseParams = ObjectGroup(
        name: "golden.Primary_GetMapValue_ResponseParams",
        instanceType: .jsGoldenPrimary_GetMapValue_ResponseParams,
        properties: [
            "result": .integer,
        ],
        methods: [:]
    )
    fileprivate static let goldenPrimarySyncGetArrayValueResponseParams = ObjectGroup(
        name: "golden.Primary_SyncGetArrayValue_ResponseParams",
        instanceType: .jsGoldenPrimary_SyncGetArrayValue_ResponseParams,
        properties: [
            "result": .float,
        ],
        methods: [:]
    )
    fileprivate static let goldenPrimarySyncGetMapValueResponseParams = ObjectGroup(
        name: "golden.Primary_SyncGetMapValue_ResponseParams",
        instanceType: .jsGoldenPrimary_SyncGetMapValue_ResponseParams,
        properties: [
            "result": .integer,
        ],
        methods: [:]
    )
}

///
/// Arrays
///
extension ILType {
    fileprivate static let jsFloatArray: ILType =
        .createJsArrayType(ofElementType: .jsFloatElement)
}

/// As Fuzzilli runs, the OperationMutator and VariadicInputReducer will modify
/// the `CreateArray` operation to increase or decrease the element count. This
/// allows arrays to be arbitrarily long.
///
/// `findOrGenerateType` is preferred over specifying `inputs` because
/// Fuzzilli only uses CodeGenerators to produce types in `inputs`, while
/// `findOrGenerateType` uses a variety of sources (e.g. `builtins`, other
/// method properties and methods). An input is specified (i.e. `.one`)
/// to prevent the CodeGenerator from being scheduled first when there are
/// no visible variables, as `findOrGenerateType` causes a crash if there
/// are no visibile variables.
private let MojoFloatArrayGenerator = CodeGenerator(
    "MojoFloatArrayGenerator",
    inputs: .one,
    produces: [.jsFloatArray]
) { b, _ in
    let elem = b.findOrGenerateType(.float)
    var elements: [Variable] = [elem]

    // Currently, arrays do not encode in anyway that their element is an
    // optional type. Since this array has an optional element type,
    // pre-populate it with elements, with a chance of loading undefined
    // for each.
    for _ in 0..<10 {
       if probability(0.5) {
           elements.append(b.loadUndefined())
       } else {
           elements.append(b.randomVariable(forUseAs: .float))
       }
    }
    b.createArray(
        with: elements,
        elementGroupName:
            ObjectGroup.floatElement.name)
}

///
/// Maps
///
extension ILType {
    fileprivate static let jsString_IntegerMap: ILType =
        .createJsMapType(
            ofKeyType: .jsStringElement,
            ofValueType: .jsIntegerElement
        )
}

/// Generate a map with only one element. As Fuzzilli runs, the OperationMutator
/// and VariadicInputReducer will modify the `CreateMap` operation to increase
/// or decrease the element count.
///
/// `findOrGenerateType` is preferred over specifying `inputs` because
/// Fuzzilli only uses CodeGenerators to produce types in `inputs`, while
/// `findOrGenerateType` uses a variety of sources (e.g. `builtins`, other
/// method properties and methods). An input is specified (i.e. `.one`)
/// to prevent the CodeGenerator from being scheduled first when there are
/// no visible variables, as `findOrGenerateType` causes a crash if there
/// are no visibile variables.
private let MojoString_IntegerMapGenerator = CodeGenerator(
    "MojoString_IntegerMapGenerator",
    inputs: .one,
    produces: [.jsString_IntegerMap]
) { b, _, _ in
    let key = b.findOrGenerateType(.jsStringElement)
    let val = b.findOrGenerateType(.jsIntegerElement)
    var keys: [Variable] = [key]
    var values: [Variable] = [val]

    // Currently, maps do not encode in anyway that their element is an optional
    // type. Since this map has an optional value type, pre-populate it with
    // elements, with a chance of loading undefined for each.
    for _ in 0..<10 {
       keys.append(b.randomVariable(forUseAs: .string))
       if probability(0.5) {
           values.append(b.loadUndefined())
       } else {
           values.append(b.randomVariable(forUseAs: .integer))
       }
    }
    b.createMap(
        withKeys: keys,
        withValues: values,
        keyGroupName: ObjectGroup.stringElement.name,
        valueGroupName: ObjectGroup.integerElement.name
    )
}

///
/// 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 goldenObserverCallbackRouter.
///
/// 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 MojoGoldenObserverRouterListenerGenerator = CodeGenerator(
    "MojoGoldenObserverRouterListenerGenerator",
    inputs: .required(.jsGoldenObserverCallbackRouter)
) { b, router in
    guard
        let eventName = ILType.jsGoldenObserverCallbackRouter.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.ObserverCallbackRouter":
       .constructor([] => .jsGoldenObserverCallbackRouter),
    "golden.SimpleStruct": .jsGoldenSimpleStructConstructor,
    "golden.Token": .jsGoldenTokenConstructor,
]

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),
        (MojoGoldenObserverRouterListenerGenerator, 5000),
        (MojoFloatArrayGenerator, 1),
    ] + commonMojoCodeGenerators,
    additionalProgramTemplates: WeightedList([]),
    disabledCodeGenerators: mojoDisabledGenerators,
    disabledMutators: [
        "ExplorationMutator", "ProbingMutator", "PropertyAccessorMutator"
    ],
    additionalBuiltins: mojoBuiltins.merging(commonMojoBuiltins) { (existing, _) in existing },
    additionalObjectGroups: [
        .goldenPrimaryRemote,
        .goldenPrimaryRemoteWrapper,
        .goldenPrimaryPendingReceiver,
        .goldenObserverCallbackRouter,
        .goldenObserverCallbackRouterReceiverHelper,
        .goldenObserverRemote,
        .goldenObserverRemoteWrapper,
        .goldenObserverPendingReceiver,
        .goldenObserverSendDelegateCallbackReceiver,
        .goldenSimpleStruct,
        .goldenToken,
        .goldenPrimaryGetArrayValueResponseParams,
        .goldenPrimaryGetMapValueResponseParams,
        .goldenPrimarySyncGetArrayValueResponseParams,
        .goldenPrimarySyncGetMapValueResponseParams,
    ] + commonMojoObjectGroups,
    additionalEnumerations: [
    ] + commonMojoEnumerations,
    additionalOptionsBags: [
    ] + commonMojoOptionsBags,
    optionalPostProcessor: nil
)