// results.test-mojom-webui.ts is auto generated by mojom_bindings_generator.py, do not edit

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

import {mojo} from '//resources/mojo/mojo/public/js/bindings.js';








export type ResultInterfacePendingReceiverEndpoint =
  mojo.internal.interfaceSupport.Endpoint<ResultInterfacePendingReceiver>;

export class ResultInterfacePendingReceiver implements
    mojo.internal.interfaceSupport.PendingReceiver<ResultInterface> {

  handle: mojo.internal.interfaceSupport.Endpoint<ResultInterfacePendingReceiver>;
  constructor(handle: MojoHandle|ResultInterfacePendingReceiverEndpoint) {
    this.handle = mojo.internal.interfaceSupport.getEndpointForReceiver(handle);
  }

  bindInBrowser(scope: string = 'context') {
    mojo.internal.interfaceSupport.bind(
        this.handle,
        'golden.ResultInterface',
        scope);
  }
}

export interface ResultInterfaceInterface {
  method(a: boolean): Promise<boolean>;
  syncMethod(a: boolean): Promise<boolean>;
}

export class ResultInterfaceRemote implements ResultInterfaceInterface {
  private proxy: mojo.internal.interfaceSupport.InterfaceRemoteBase<ResultInterfacePendingReceiver>;
  $: mojo.internal.interfaceSupport.InterfaceRemoteBaseWrapper<ResultInterfacePendingReceiver>;
  onConnectionError: mojo.internal.interfaceSupport.ConnectionErrorEventRouter;

  constructor(
      handle?: MojoHandle|ResultInterfacePendingReceiverEndpoint) {
    this.proxy =
        new mojo.internal.interfaceSupport.InterfaceRemoteBase(
          ResultInterfacePendingReceiver, handle);

    this.$ = new mojo.internal.interfaceSupport.InterfaceRemoteBaseWrapper(this.proxy);

    this.onConnectionError = this.proxy.getConnectionErrorEventRouter();
  }

  method(
      a: boolean): Promise<boolean> {
    return this.proxy.sendMessage(
        0,
        ResultInterface_Method_ParamsSpec.$,
        ResultInterface_Method_ResponseParamsSpec.$,
        [
          a
        ],
        true);
  }

  syncMethod(
      a: boolean): Promise<boolean> {
    return this.proxy.sendMessage(
        1,
        ResultInterface_SyncMethod_ParamsSpec.$,
        ResultInterface_SyncMethod_ResponseParamsSpec.$,
        [
          a
        ],
        true);
  }
};

/**
 * An object which receives request messages for the ResultInterface
 * mojom interface. Must be constructed over an object which implements that
 * interface.
 */
export class ResultInterfaceReceiver {
  private helper_internal_: mojo.internal.interfaceSupport.InterfaceReceiverHelperInternal<
    ResultInterfaceRemote, ResultInterfacePendingReceiver>;

  $: mojo.internal.interfaceSupport.InterfaceReceiverHelper<
    ResultInterfaceRemote, ResultInterfacePendingReceiver>;

  onConnectionError: mojo.internal.interfaceSupport.ConnectionErrorEventRouter;


  constructor(impl: ResultInterfaceInterface) {

    this.helper_internal_ = new mojo.internal.interfaceSupport.InterfaceReceiverHelperInternal(
        ResultInterfaceRemote);

    this.$ = new mojo.internal.interfaceSupport.InterfaceReceiverHelper(this.helper_internal_);


    this.helper_internal_.registerHandler(
        0,
        ResultInterface_Method_ParamsSpec.$,
        ResultInterface_Method_ResponseParamsSpec.$,
        impl.method.bind(impl),
        true);
    this.helper_internal_.registerHandler(
        1,
        ResultInterface_SyncMethod_ParamsSpec.$,
        ResultInterface_SyncMethod_ResponseParamsSpec.$,
        impl.syncMethod.bind(impl),
        true);
    this.onConnectionError = this.helper_internal_.getConnectionErrorEventRouter();
  }
}

export class ResultInterface {
  static get $interfaceName(): string {
    return "golden.ResultInterface";
  }

  /**
   * Returns a remote for this interface which sends messages to the browser.
   * The browser must have an interface request binder registered for this
   * interface and accessible to the calling document's frame.
   */
  static getRemote(): ResultInterfaceRemote {
    let remote = new ResultInterfaceRemote;
    remote.$.bindNewPipeAndPassReceiver().bindInBrowser();
    return remote;
  }
}

/**
 * An object which receives request messages for the ResultInterface
 * mojom interface and dispatches them as callbacks. One callback receiver exists
 * on this object for each message defined in the mojom interface, and each
 * receiver can have any number of listeners added to it.
 */
export class ResultInterfaceCallbackRouter {
  private helper_internal_: mojo.internal.interfaceSupport.InterfaceReceiverHelperInternal<
    ResultInterfaceRemote, ResultInterfacePendingReceiver>;
  $: mojo.internal.interfaceSupport.InterfaceReceiverHelper<
    ResultInterfaceRemote, ResultInterfacePendingReceiver>;
  router_: mojo.internal.interfaceSupport.CallbackRouter;

  method: mojo.internal.interfaceSupport.InterfaceCallbackReceiver<
    (a: boolean,) => any>;
  syncMethod: mojo.internal.interfaceSupport.InterfaceCallbackReceiver<
    (a: boolean,) => any>;
  onConnectionError: mojo.internal.interfaceSupport.ConnectionErrorEventRouter;

  constructor() {
    this.helper_internal_ = new mojo.internal.interfaceSupport.InterfaceReceiverHelperInternal(
      ResultInterfaceRemote);

    this.$ = new mojo.internal.interfaceSupport.InterfaceReceiverHelper(this.helper_internal_);

    this.router_ = new mojo.internal.interfaceSupport.CallbackRouter;

    this.method =
        new mojo.internal.interfaceSupport.InterfaceCallbackReceiver(
            this.router_);

    this.helper_internal_.registerHandler(
        0,
        ResultInterface_Method_ParamsSpec.$,
        ResultInterface_Method_ResponseParamsSpec.$,
        this.method.createReceiverHandler(true /* expectsResponse */),
        true);
    this.syncMethod =
        new mojo.internal.interfaceSupport.InterfaceCallbackReceiver(
            this.router_);

    this.helper_internal_.registerHandler(
        1,
        ResultInterface_SyncMethod_ParamsSpec.$,
        ResultInterface_SyncMethod_ResponseParamsSpec.$,
        this.syncMethod.createReceiverHandler(true /* expectsResponse */),
        true);
    this.onConnectionError = this.helper_internal_.getConnectionErrorEventRouter();
  }

  /**
   * @param id An ID returned by a prior call to addListener.
   * @return True iff the identified listener was found and removed.
   */
  removeListener(id: number): boolean {
    return this.router_.removeListener(id);
  }
}

export const ResultTestErrorSpec: { $: mojo.internal.MojomType } =
    { $: {} as unknown as mojo.internal.MojomType };

export const ResultInterface_Method_ParamsSpec: { $: mojo.internal.MojomType } =
    { $: {} as unknown as mojo.internal.MojomType };

export const ResultInterface_Method_ResponseParamsSpec: { $: mojo.internal.MojomType } =
    { $: {} as unknown as mojo.internal.MojomType };

export const ResultInterface_SyncMethod_ParamsSpec: { $: mojo.internal.MojomType } =
    { $: {} as unknown as mojo.internal.MojomType };

export const ResultInterface_SyncMethod_ResponseParamsSpec: { $: mojo.internal.MojomType } =
    { $: {} as unknown as mojo.internal.MojomType };

export const ResultInterface_Method_ResponseParam_ResultSpec: { $: mojo.internal.MojomType } =
    { $: {} as unknown as mojo.internal.MojomType };

export const ResultInterface_SyncMethod_ResponseParam_ResultSpec: { $: mojo.internal.MojomType } =
    { $: {} as unknown as mojo.internal.MojomType };




export interface ResultTestErrorMojoType {
}


export type ResultTestError = ResultTestErrorMojoType;
mojo.internal.Struct<ResultTestErrorMojoType>(
    ResultTestErrorSpec.$,
    'ResultTestError',
    [
    ],
    [[0, 8],]);





export interface ResultInterface_Method_ParamsMojoType {
  a: boolean;
}


export type ResultInterface_Method_Params = ResultInterface_Method_ParamsMojoType;
mojo.internal.Struct<ResultInterface_Method_ParamsMojoType>(
    ResultInterface_Method_ParamsSpec.$,
    'ResultInterface_Method_Params',
    [
      mojo.internal.StructField<ResultInterface_Method_ParamsMojoType, boolean>(
        'a', 0,
        0,
        mojo.internal.Bool,
        false,
        false /* nullable */,
        0,
        undefined,
        undefined,
    ),
    ],
    [[0, 16],]);





export interface ResultInterface_Method_ResponseParamsMojoType {
  result: ResultInterface_Method_ResponseParam_Result;
}


export type ResultInterface_Method_ResponseParams = ResultInterface_Method_ResponseParamsMojoType;
mojo.internal.Struct<ResultInterface_Method_ResponseParamsMojoType>(
    ResultInterface_Method_ResponseParamsSpec.$,
    'ResultInterface_Method_ResponseParams',
    [
      mojo.internal.StructField<ResultInterface_Method_ResponseParamsMojoType, ResultInterface_Method_ResponseParam_Result>(
        'result', 0,
        0,
        ResultInterface_Method_ResponseParam_ResultSpec.$,
        null,
        false /* nullable */,
        0,
        undefined,
        undefined,
    ),
    ],
    [[0, 24],]);





export interface ResultInterface_SyncMethod_ParamsMojoType {
  a: boolean;
}


export type ResultInterface_SyncMethod_Params = ResultInterface_SyncMethod_ParamsMojoType;
mojo.internal.Struct<ResultInterface_SyncMethod_ParamsMojoType>(
    ResultInterface_SyncMethod_ParamsSpec.$,
    'ResultInterface_SyncMethod_Params',
    [
      mojo.internal.StructField<ResultInterface_SyncMethod_ParamsMojoType, boolean>(
        'a', 0,
        0,
        mojo.internal.Bool,
        false,
        false /* nullable */,
        0,
        undefined,
        undefined,
    ),
    ],
    [[0, 16],]);





export interface ResultInterface_SyncMethod_ResponseParamsMojoType {
  result: ResultInterface_SyncMethod_ResponseParam_Result;
}


export type ResultInterface_SyncMethod_ResponseParams = ResultInterface_SyncMethod_ResponseParamsMojoType;
mojo.internal.Struct<ResultInterface_SyncMethod_ResponseParamsMojoType>(
    ResultInterface_SyncMethod_ResponseParamsSpec.$,
    'ResultInterface_SyncMethod_ResponseParams',
    [
      mojo.internal.StructField<ResultInterface_SyncMethod_ResponseParamsMojoType, ResultInterface_SyncMethod_ResponseParam_Result>(
        'result', 0,
        0,
        ResultInterface_SyncMethod_ResponseParam_ResultSpec.$,
        null,
        false /* nullable */,
        0,
        undefined,
        undefined,
    ),
    ],
    [[0, 24],]);



mojo.internal.Union(
    ResultInterface_Method_ResponseParam_ResultSpec.$, 'ResultInterface_Method_ResponseParam_Result',
    {
      'success': {
        'ordinal': 0,
        'type': mojo.internal.Bool,
      },
      'failure': {
        'ordinal': 1,
        'type': ResultTestErrorSpec.$,
      },
    });

export interface ResultInterface_Method_ResponseParam_Result {
  success?: boolean,
  failure?: ResultTestError,
}

export enum ResultInterface_Method_ResponseParam_ResultFieldTags {
  SUCCESS,
  FAILURE,
}

export function whichResultInterface_Method_ResponseParam_Result(u: ResultInterface_Method_ResponseParam_Result): ResultInterface_Method_ResponseParam_ResultFieldTags {
  if (u.success !== null && u.success !== undefined) {
    return ResultInterface_Method_ResponseParam_ResultFieldTags.SUCCESS;
  }
  if (u.failure !== null && u.failure !== undefined) {
    return ResultInterface_Method_ResponseParam_ResultFieldTags.FAILURE;
  }
  throw new Error("no union field has been set, this is an illegal state");
}
mojo.internal.Union(
    ResultInterface_SyncMethod_ResponseParam_ResultSpec.$, 'ResultInterface_SyncMethod_ResponseParam_Result',
    {
      'success': {
        'ordinal': 0,
        'type': mojo.internal.Bool,
      },
      'failure': {
        'ordinal': 1,
        'type': ResultTestErrorSpec.$,
      },
    });

export interface ResultInterface_SyncMethod_ResponseParam_Result {
  success?: boolean,
  failure?: ResultTestError,
}

export enum ResultInterface_SyncMethod_ResponseParam_ResultFieldTags {
  SUCCESS,
  FAILURE,
}

export function whichResultInterface_SyncMethod_ResponseParam_Result(u: ResultInterface_SyncMethod_ResponseParam_Result): ResultInterface_SyncMethod_ResponseParam_ResultFieldTags {
  if (u.success !== null && u.success !== undefined) {
    return ResultInterface_SyncMethod_ResponseParam_ResultFieldTags.SUCCESS;
  }
  if (u.failure !== null && u.failure !== undefined) {
    return ResultInterface_SyncMethod_ResponseParam_ResultFieldTags.FAILURE;
  }
  throw new Error("no union field has been set, this is an illegal state");
}
