// basic_union.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 const EnumInUnionSpec: { $: mojo.internal.MojomType } = { $: mojo.internal.Enum() };

export enum EnumInUnion {

  MIN_VALUE = 0,
  MAX_VALUE = 1,
  kThis = 0,
  kThat = 1,
}


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

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




export interface StructInUnionMojoType {
  flag: boolean;
  value: string;
}


export type StructInUnion = StructInUnionMojoType;
mojo.internal.Struct<StructInUnionMojoType>(
    StructInUnionSpec.$,
    'StructInUnion',
    [
      mojo.internal.StructField<StructInUnionMojoType, boolean>(
        'flag', 0,
        0,
        mojo.internal.Bool,
        false,
        false /* nullable */,
        0,
        undefined,
        undefined,
    ),
      mojo.internal.StructField<StructInUnionMojoType, string>(
        'value', 8,
        0,
        mojo.internal.String,
        null,
        false /* nullable */,
        0,
        undefined,
        undefined,
    ),
    ],
    [[0, 24],]);



mojo.internal.Union(
    BasicUnionSpec.$, 'BasicUnion',
    {
      'numericValue': {
        'ordinal': 0,
        'type': mojo.internal.Int32,
      },
      'enumValue': {
        'ordinal': 1,
        'type': EnumInUnionSpec.$,
      },
      'structValue': {
        'ordinal': 2,
        'type': StructInUnionSpec.$,
      },
    });

export interface BasicUnion {
  numericValue?: number,
  enumValue?: EnumInUnion,
  structValue?: StructInUnion,
}

export enum BasicUnionFieldTags {
  NUMERIC_VALUE,
  ENUM_VALUE,
  STRUCT_VALUE,
}

export function whichBasicUnion(u: BasicUnion): BasicUnionFieldTags {
  if (u.numericValue !== null && u.numericValue !== undefined) {
    return BasicUnionFieldTags.NUMERIC_VALUE;
  }
  if (u.enumValue !== null && u.enumValue !== undefined) {
    return BasicUnionFieldTags.ENUM_VALUE;
  }
  if (u.structValue !== null && u.structValue !== undefined) {
    return BasicUnionFieldTags.STRUCT_VALUE;
  }
  throw new Error("no union field has been set, this is an illegal state");
}
