{"version":3,"sources":["src/common.speech/ServiceMessages/TranslationHypothesis.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAIhE,MAAM,WAAW,sBAAsB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,gBAAgB,CAAC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,aAAa,CAAC;CAC9B;AAED,qBAAa,qBAAsB,YAAW,sBAAsB;IAChE,OAAO,CAAC,yBAAyB,CAAyB;IAE1D,OAAO;WAMO,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,qBAAqB;WAIjE,uBAAuB,CAAC,qBAAqB,EAAE;QAAE,gBAAgB,EAAE,sBAAsB,CAAA;KAAE,EAAE,UAAU,EAAE,MAAM,GAAG,qBAAqB;IAQrJ,IAAW,QAAQ,IAAI,MAAM,CAE5B;IAED,IAAW,MAAM,IAAI,MAAM,CAE1B;IAED,IAAW,IAAI,IAAI,MAAM,CAExB;IAED,IAAW,WAAW,IAAI,aAAa,CAEtC;IAED,IAAW,QAAQ,IAAI,MAAM,CAE5B;IAEM,MAAM,IAAI,MAAM;IAUvB,OAAO,CAAC,oBAAoB;CAO/B","file":"TranslationHypothesis.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport { Contracts } from \"../../sdk/Contracts.js\";\nimport { IPrimaryLanguage, ITranslations } from \"../Exports.js\";\nimport { TranslationStatus } from \"../TranslationStatus.js\";\n\n// translation.hypothesis\nexport interface ITranslationHypothesis {\n    Duration: number;\n    Offset: number;\n    PrimaryLanguage?: IPrimaryLanguage;\n    Text: string;\n    Translation: ITranslations;\n}\n\nexport class TranslationHypothesis implements ITranslationHypothesis {\n    private privTranslationHypothesis: ITranslationHypothesis;\n\n    private constructor(hypothesis: ITranslationHypothesis, baseOffset: number) {\n        this.privTranslationHypothesis = hypothesis;\n        this.privTranslationHypothesis.Offset += baseOffset;\n        this.privTranslationHypothesis.Translation.TranslationStatus = this.mapTranslationStatus(this.privTranslationHypothesis.Translation.TranslationStatus);\n    }\n\n    public static fromJSON(json: string, baseOffset: number): TranslationHypothesis {\n        return new TranslationHypothesis(JSON.parse(json) as ITranslationHypothesis, baseOffset);\n    }\n\n    public static fromTranslationResponse(translationHypothesis: { SpeechHypothesis: ITranslationHypothesis }, baseOffset: number): TranslationHypothesis {\n        Contracts.throwIfNullOrUndefined(translationHypothesis, \"translationHypothesis\");\n        const hypothesis: ITranslationHypothesis = translationHypothesis.SpeechHypothesis;\n        translationHypothesis.SpeechHypothesis = undefined;\n        hypothesis.Translation = (translationHypothesis as unknown as ITranslations);\n        return new TranslationHypothesis(hypothesis, baseOffset);\n    }\n\n    public get Duration(): number {\n        return this.privTranslationHypothesis.Duration;\n    }\n\n    public get Offset(): number {\n        return this.privTranslationHypothesis.Offset;\n    }\n\n    public get Text(): string {\n        return this.privTranslationHypothesis.Text;\n    }\n\n    public get Translation(): ITranslations {\n        return this.privTranslationHypothesis.Translation;\n    }\n\n    public get Language(): string {\n        return this.privTranslationHypothesis.PrimaryLanguage?.Language;\n    }\n\n    public asJson(): string {\n        const jsonObj = { ...this.privTranslationHypothesis };\n        // Convert the enum value to its string representation for serialization purposes.\n\n        return jsonObj.Translation !== undefined ? JSON.stringify({\n            ...jsonObj,\n            TranslationStatus: TranslationStatus[jsonObj.Translation.TranslationStatus] as keyof typeof TranslationStatus\n        }) : JSON.stringify(jsonObj);\n    }\n\n    private mapTranslationStatus(status: any): TranslationStatus {\n        if (typeof status === \"string\") {\n            return TranslationStatus[status as keyof typeof TranslationStatus];\n        } else if (typeof status === \"number\") {\n            return status;\n        }\n    }\n}\n"]}