// typemap.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';


import {
  TypemappedDataView,
  TypemappedTypeMapper,
} from './typemap.test-mojom-converters.js';



import { Converter } from './converter.js';



export type IFaceWithTypemapPendingReceiverEndpoint =
  mojo.internal.interfaceSupport.Endpoint<IFaceWithTypemapPendingReceiver>;

export class IFaceWithTypemapPendingReceiver implements
    mojo.internal.interfaceSupport.PendingReceiver<IFaceWithTypemap> {

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

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

export interface IFaceWithTypemapInterface {
  echo(param: number): Promise<{
        out: number, }>;
}

export class IFaceWithTypemapRemote implements IFaceWithTypemapInterface {
  private proxy: mojo.internal.interfaceSupport.InterfaceRemoteBase<IFaceWithTypemapPendingReceiver>;
  $: mojo.internal.interfaceSupport.InterfaceRemoteBaseWrapper<IFaceWithTypemapPendingReceiver>;
  onConnectionError: mojo.internal.interfaceSupport.ConnectionErrorEventRouter;

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

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

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

  echo(
      param: number): Promise<{
        out: number, }> {
    return this.proxy.sendMessage(
        0,
        IFaceWithTypemap_Echo_ParamsSpec.$,
        IFaceWithTypemap_Echo_ResponseParamsSpec.$,
        [
          param
        ],
        false);
  }
};

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

  $: mojo.internal.interfaceSupport.InterfaceReceiverHelper<
    IFaceWithTypemapRemote, IFaceWithTypemapPendingReceiver>;

  onConnectionError: mojo.internal.interfaceSupport.ConnectionErrorEventRouter;


  constructor(impl: IFaceWithTypemapInterface) {

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

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


    this.helper_internal_.registerHandler(
        0,
        IFaceWithTypemap_Echo_ParamsSpec.$,
        IFaceWithTypemap_Echo_ResponseParamsSpec.$,
        impl.echo.bind(impl),
        false);
    this.onConnectionError = this.helper_internal_.getConnectionErrorEventRouter();
  }
}

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

  /**
   * 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(): IFaceWithTypemapRemote {
    let remote = new IFaceWithTypemapRemote;
    remote.$.bindNewPipeAndPassReceiver().bindInBrowser();
    return remote;
  }
}

/**
 * An object which receives request messages for the IFaceWithTypemap
 * 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 IFaceWithTypemapCallbackRouter {
  private helper_internal_: mojo.internal.interfaceSupport.InterfaceReceiverHelperInternal<
    IFaceWithTypemapRemote, IFaceWithTypemapPendingReceiver>;
  $: mojo.internal.interfaceSupport.InterfaceReceiverHelper<
    IFaceWithTypemapRemote, IFaceWithTypemapPendingReceiver>;
  router_: mojo.internal.interfaceSupport.CallbackRouter;

  echo: mojo.internal.interfaceSupport.InterfaceCallbackReceiver<
    (param: number,) => any>;
  onConnectionError: mojo.internal.interfaceSupport.ConnectionErrorEventRouter;

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

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

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

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

    this.helper_internal_.registerHandler(
        0,
        IFaceWithTypemap_Echo_ParamsSpec.$,
        IFaceWithTypemap_Echo_ResponseParamsSpec.$,
        this.echo.createReceiverHandler(true /* expectsResponse */),
        false);
    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 TypemappedSpec: { $: mojo.internal.MojomType } =
    { $: {} as unknown as mojo.internal.MojomType };

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

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




export interface TypemappedMojoType {
  field: number;
  optional: (number | null);
  optionalContainer: Array<(boolean | null)>;
}

export type Typemapped = number;

const converterForTypemapped: TypemappedTypeMapper<number>
    = new Converter();

mojo.internal.TypemappedStruct<number, TypemappedMojoType> (
    TypemappedSpec.$,
    'Typemapped',
    TypemappedDataView,
    converterForTypemapped,
    [
      mojo.internal.StructField<number, number>(
        'field', 0,
        0,
        mojo.internal.Uint8,
        0,
        false /* nullable */,
        0,
        undefined,
        ((value: number) => converterForTypemapped.field(value)),
    ),
      mojo.internal.StructField<number, boolean>(
        'optional_$flag', 1,
        0,
        mojo.internal.Bool,
        false,
        false /* nullable */,
        0,
        {
          isPrimary: true,
          linkedValueFieldName: "optional_$value",
          originalFieldName: "optional",
        },
        ((value: number) => converterForTypemapped.optional(value) !== null),
    ),
      mojo.internal.StructField<number, number>(
        'optional_$value', 4,
        0,
        mojo.internal.Int32,
        0,
        false /* nullable */,
        0,
        {
          isPrimary: false,
          originalFieldName: "optional",
        },

        ((value: number) => converterForTypemapped.optional(value)),
    ),
      mojo.internal.StructField<number, Array<(boolean | null)>>(
        'optionalContainer', 8,
        0,
        mojo.internal.Array(mojo.internal.Bool, true),
        null,
        false /* nullable */,
        0,
        undefined,
        ((value: number) => converterForTypemapped.optionalContainer(value)),
    ),
    ],
    [[0, 24],]);





export interface IFaceWithTypemap_Echo_ParamsMojoType {
  param: number;
}


export type IFaceWithTypemap_Echo_Params = IFaceWithTypemap_Echo_ParamsMojoType;
mojo.internal.Struct<IFaceWithTypemap_Echo_ParamsMojoType>(
    IFaceWithTypemap_Echo_ParamsSpec.$,
    'IFaceWithTypemap_Echo_Params',
    [
      mojo.internal.StructField<IFaceWithTypemap_Echo_ParamsMojoType, number>(
        'param', 0,
        0,
        TypemappedSpec.$,
        null,
        false /* nullable */,
        0,
        undefined,
        undefined,
    ),
    ],
    [[0, 16],]);





export interface IFaceWithTypemap_Echo_ResponseParamsMojoType {
  out: number;
}


export type IFaceWithTypemap_Echo_ResponseParams = IFaceWithTypemap_Echo_ResponseParamsMojoType;
mojo.internal.Struct<IFaceWithTypemap_Echo_ResponseParamsMojoType>(
    IFaceWithTypemap_Echo_ResponseParamsSpec.$,
    'IFaceWithTypemap_Echo_ResponseParams',
    [
      mojo.internal.StructField<IFaceWithTypemap_Echo_ResponseParamsMojoType, number>(
        'out', 0,
        0,
        TypemappedSpec.$,
        null,
        false /* nullable */,
        0,
        undefined,
        undefined,
    ),
    ],
    [[0, 16],]);



