/**
 * Copyright 2018 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ import * as Api from '../../api/v2' ; import { NewSurfaceArgument , PermissionArgument , OptionArgument , ConfirmationArgument , DateTimeArgument , SignInArgument , PlaceArgument , TransactionDecisionArgument , TransactionRequirementsArgument , DeliveryAddressArgument , RegisterUpdateArgument , UpdatePermissionUserIdArgument , CompletePurchaseArgument , DigitalPurchaseCheckArgument , } from '..' ; import { RepromptArgument , FinalRepromptArgument } from './noinput' ; import { MediaStatusArgument } from './media' ; import { ApiClientObjectMap } from '../../../../common' ; export { ApiClientObjectMap } ; public export type Argument = Api . GoogleActionsV2Argument [ keyof Api . GoogleActionsV2Argument ] ; export interface ArgumentsNamed { /**
     * True if the request follows a previous request asking for
     * permission from the user and the user granted the permission(s).
     * Otherwise, false.
     * Only use after calling  Permission * or  UpdatePermission .
     *  public PERMISSION ? : PermissionArgument ; /**
     * The option key user chose from options response.
     * Only use after calling  List * or  Carousel .
     *  public OPTION ? : OptionArgument ; /**
     * The transactability of user.
     * Only use after calling  TransactionRequirements .
     * Undefined if no result given.
     *  public TRANSACTION_REQUIREMENTS_CHECK_RESULT ? : TransactionRequirementsArgument ; /**
     * The order delivery address.
     * Only use after calling  DeliveryAddress .
     *  public DELIVERY_ADDRESS_VALUE ? : DeliveryAddressArgument ; /**
     * The transaction decision information.
     * Is object with userDecision only if user declines.
     * userDecision will be one of  GoogleActionsV2TransactionDecisionValueUserDecision .
     * Only use after calling  TransactionDecision .
     *  public TRANSACTION_DECISION_VALUE ? : TransactionDecisionArgument ; /**
     * The complete purchase information.
     * Only use after calling  CompletePurchase .
     *  public COMPLETE_PURCHASE_VALUE ? : CompletePurchaseArgument ; /**
     * Only use after calling  DigitalPurchaseCheck .
     *  public DIGITAL_PURCHASE_CHECK_RESULT ? : DigitalPurchaseCheckArgument ; /**
     * The confirmation decision.
     * Use after  Confirmation public CONFIRMATION ? : ConfirmationArgument ; /**
     * The user provided date and time.
     * Use after  DateTime public DATETIME ? : DateTimeArgument ; /**
     * The status of user sign in request.
     * Use after  SignIn public SIGN_IN ? : SignInArgument ; public REPROMPT_COUNT ? : RepromptArgument ; public IS_FINAL_REPROMPT ? : FinalRepromptArgument ; /**
     * The result of  NewSurface * True if user has triggered conversation on a new device following the
     * `actions.intent.NEW_SURFACE` intent.
     *  public NEW_SURFACE ? : NewSurfaceArgument ; /**
     * True if user accepted update registration request.
     * Used with  RegisterUpdate public REGISTER_UPDATE ? : RegisterUpdateArgument ; /**
     * The updates user id.
     * Only use after calling  UpdatePermission .
     *  public UPDATES_USER_ID ? : UpdatePermissionUserIdArgument ; /**
     * The user provided place.
     * Use after  Place .
     *  public PLACE ? : PlaceArgument ; public MEDIA_STATUS ? : MediaStatusArgument ; } export interface ArgumentsParsed extends ArgumentsNamed { public [ name ] : Argument | undefined ; } hidden export interface ArgumentsIndexable { [ key ] : Argument ; } export interface ArgumentsStatus { public [ name ] : Api . GoogleRpcStatus | undefined ; } export interface ArgumentsRaw { public [ name ] : Api . GoogleActionsV2Argument ; } const getValue = ( arg ) : Argument => { for ( const key in arg ) { if ( key === 'name' || key === 'textValue' || key === 'status' ) { continue ; } return ( arg as ArgumentsIndexable ) [ key ] ; } if ( arg . name === 'PERMISSION' ) { return ! ! arg . boolValue ; } return arg . textValue ; } ; export class Parsed { public list : Argument [ ] ; public input : ArgumentsParsed = { } ; hidden constructor ( raw ) { this . list = raw . map ( ( arg , i ) => { const value = getValue ( arg ) ; const name = arg . name ! ; this . input [ name ] = value ; return value ; } ) ; } public get < TName extends keyof ArgumentsNamed > ( name ) ; public get ( name ) ; get ( name ) { return this . input [ name ] ; } } export class Status { public list : ( Api . GoogleRpcStatus | undefined ) [ ] ; public input : ArgumentsStatus = { } ; hidden constructor ( raw ) { this . list = raw . map ( ( arg , i ) => { const name = arg . name ! ; const status = arg . status ; this . input [ name ] = status ; return status ; } ) ; } public get ( name ) { return this . input [ name ] ; } } export class Raw { public input : ArgumentsRaw ; hidden constructor ( public list ) { this . input = list . reduce ( ( o , arg ) => { o [ arg . name ! ] = arg ; return o ; } , { } as ArgumentsRaw ) ; } public get ( name ) { return this . input [ name ] ; } } export class Arguments { public parsed : Parsed ; public status : Status ; public raw : Raw ; hidden constructor ( raw = [ ] ) { this . parsed = new Parsed ( raw ) ; this . status = new Status ( raw ) ; this . raw = new Raw ( raw ) ; } example param argument return public get < TName extends keyof ArgumentsNamed > ( name ) ; public get ( name ) ; get ( name ) { return this . parsed . get ( name ) ; } public [ Symbol . iterator ] ( ) { return this . raw . list [ Symbol . iterator ] ( ) ; } }