/**
 * 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' ; public export interface MediaObjectOptions { public url : string ; public description ? : string ; public name ? : string ; public icon ? : Api . GoogleActionsV2UiElementsImage ; public image ? : Api . GoogleActionsV2UiElementsImage ; } const toMediaObject = ( object ) => { if ( typeof object === 'string' ) { return new MediaObject ( object ) ; } return object ; } ; public export interface MediaObject extends Api . GoogleActionsV2MediaObject { } export class MediaObject implements Api . GoogleActionsV2MediaObject { param options public constructor ( options ) { if ( typeof options === 'string' ) { this . contentUrl = options ; return ; } this . contentUrl = options . url ; this . description = options . description ; this . icon = options . icon ; this . largeImage = options . image ; this . name = options . name ; } } export type MediaObjectString = Api . GoogleActionsV2MediaObject | string ; public export interface MediaResponseOptions { public objects : MediaObjectString [ ] ; public type ? : Api . GoogleActionsV2MediaResponseMediaType ; } const isOptions = ( options ) : options is MediaResponseOptions => { const test = options as MediaResponseOptions ; return Array . isArray ( test . objects ) ; } ; public export interface MediaResponse extends Api . GoogleActionsV2MediaResponse { } export class MediaResponse implements Api . GoogleActionsV2MediaResponse { param options public constructor ( options ) ; param objects public constructor ( objects ) ; param objects public constructor ( ... objects ) ; constructor ( options ? , ... objects ) { this . mediaType = 'AUDIO' ; if ( ! options ) { this . mediaObjects = [ ] ; return ; } if ( Array . isArray ( options ) ) { this . mediaObjects = options . map ( o => toMediaObject ( o ) ) ; return ; } if ( isOptions ( options ) ) { this . mediaType = options . type || this . mediaType ; this . mediaObjects = options . objects . map ( o => toMediaObject ( o ) ) ; return ; } this . mediaObjects = [ options ] . concat ( objects ) . map ( o => toMediaObject ( o ) ) ; } }