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0C,SAAQ,uBAAuB;IAElF,OAAO;IAIP;;;;;;;OAOG;WACW,UAAU,CAAC,MAAM,EAAE,4BAA4B,GAAG,yCAAyC;CAU5G","file":"VoiceProfileEnrollmentResult.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT license.\r\n\r\nimport { CancellationErrorCodePropertyName } from \"../common.speech/Exports\";\r\nimport { Contracts } from \"./Contracts\";\r\nimport {\r\n    CancellationDetailsBase,\r\n    CancellationErrorCode,\r\n    CancellationReason,\r\n    PropertyCollection,\r\n    ResultReason,\r\n} from \"./Exports\";\r\n\r\nexport interface EnrollmentResultDetails {\r\n    profileId: string;\r\n    enrollmentsCount: number;\r\n    enrollmentsLengthInSec: number;\r\n    enrollmentsSpeechLengthInSec: number;\r\n    remainingEnrollmentsCount: number;\r\n    remainingEnrollmentsSpeechLengthInSec: number;\r\n    audioLengthInSec: number;\r\n    audioSpeechLengthInSec: number;\r\n    enrollmentStatus: string;\r\n}\r\n\r\n/**\r\n * Output format\r\n * @class VoiceProfileEnrollmentResult\r\n */\r\nexport class VoiceProfileEnrollmentResult {\r\n    private privReason: ResultReason;\r\n    private privDetails: EnrollmentResultDetails;\r\n    private privProperties: PropertyCollection;\r\n    private privErrorDetails: string;\r\n\r\n    public constructor(reason: ResultReason, json: string, statusText: string) {\r\n        this.privReason = reason;\r\n        this.privProperties = new PropertyCollection();\r\n        if (this.privReason !== ResultReason.Canceled) {\r\n            if (!!json) {\r\n                this.privDetails = JSON.parse(json);\r\n                if (this.privDetails.enrollmentStatus.toLowerCase() === \"enrolling\") {\r\n                    this.privReason = ResultReason.EnrollingVoiceProfile;\r\n                }\r\n            }\r\n        } else {\r\n            this.privErrorDetails = statusText;\r\n            this.privProperties.setProperty(CancellationErrorCodePropertyName, CancellationErrorCode[CancellationErrorCode.ServiceError]);\r\n        }\r\n    }\r\n\r\n    public static FromIdentificationProfileList(json: { value: any[] }): VoiceProfileEnrollmentResult[] {\r\n        const results: VoiceProfileEnrollmentResult[] = [];\r\n        for (const item of json.value) {\r\n            const reason: ResultReason = item.enrollmentStatus.toLowerCase() === \"enrolling\" ?\r\n                ResultReason.EnrollingVoiceProfile : item.enrollmentStatus.toLowerCase() === \"enrolled\" ?\r\n                ResultReason.EnrolledVoiceProfile : ResultReason.Canceled;\r\n            const result = new VoiceProfileEnrollmentResult(reason, null, null);\r\n            result.privDetails = this.getIdentificationDetails(item);\r\n            results.push(result);\r\n        }\r\n        return results;\r\n    }\r\n\r\n    public static FromVerificationProfileList(json: { value: any[] }): VoiceProfileEnrollmentResult[] {\r\n        const results: VoiceProfileEnrollmentResult[] = [];\r\n        for (const item of json.value) {\r\n            const reason: ResultReason = item.enrollmentStatus.toLowerCase() === \"enrolling\" ?\r\n                ResultReason.EnrollingVoiceProfile : item.enrollmentStatus.toLowerCase() === \"enrolled\" ?\r\n                ResultReason.EnrolledVoiceProfile : ResultReason.Canceled;\r\n            const result = new VoiceProfileEnrollmentResult(reason, null, null);\r\n            result.privDetails = this.getVerificationDetails(item);\r\n            results.push(result);\r\n        }\r\n        return results;\r\n    }\r\n\r\n    public get reason(): ResultReason {\r\n        return this.privReason;\r\n    }\r\n\r\n    public get enrollmentsCount(): number {\r\n        return this.privDetails.enrollmentsCount;\r\n    }\r\n\r\n    public get enrollmentsLengthInSec(): number {\r\n        return this.privDetails.enrollmentsLengthInSec;\r\n    }\r\n\r\n    public get properties(): PropertyCollection {\r\n        return this.privProperties;\r\n    }\r\n\r\n    public get enrollmentResultDetails(): EnrollmentResultDetails {\r\n        return this.privDetails;\r\n    }\r\n\r\n    public get errorDetails(): string {\r\n        return this.privErrorDetails;\r\n    }\r\n\r\n    private static getIdentificationDetails(json: any): any {\r\n        return {\r\n            audioLengthInSec: json.audioLengthInSec ? parseFloat(json.audioLengthInSec) : 0,\r\n            audioSpeechLengthInSec: json.audioSpeechLengthInSec ? parseFloat(json.audioSpeechLengthInSec) : 0,\r\n            enrollmentStatus: json.enrollmentStatus,\r\n            enrollmentsCount: json.enrollmentsCount || 0,\r\n            enrollmentsLengthInSec: json.enrollmentsLengthInSec ? parseFloat(json.enrollmentsLengthInSec) : 0,\r\n            enrollmentsSpeechLengthInSec: json.enrollmentsSpeechLengthInSec ? parseFloat(json.enrollmentsSpeechLengthInSec) : 0,\r\n            profileId: json.profileId || json.identificationProfileId,\r\n            remainingEnrollmentsSpeechLengthInSec: json.remainingEnrollmentsSpeechLengthInSec ? parseFloat(json.remainingEnrollmentsSpeechLengthInSec) : 0\r\n        };\r\n    }\r\n\r\n    private static getVerificationDetails(json: any): any {\r\n        return {\r\n            audioLengthInSec: json.audioLengthInSec ? parseFloat(json.audioLengthInSec) : 0,\r\n            audioSpeechLengthInSec: json.audioSpeechLengthInSec ? parseFloat(json.audioSpeechLengthInSec) : 0,\r\n            enrollmentStatus: json.enrollmentStatus,\r\n            enrollmentsCount: json.enrollmentsCount,\r\n            enrollmentsLengthInSec: json.enrollmentsLengthInSec ? parseFloat(json.enrollmentsLengthInSec) : 0,\r\n            enrollmentsSpeechLengthInSec: json.enrollmentsSpeechLengthInSec ? parseFloat(json.enrollmentsSpeechLengthInSec) : 0,\r\n            profileId: json.profileId || json.verificationProfileId,\r\n            remainingEnrollmentsCount: json.remainingEnrollments || json.remainingEnrollmentsCount,\r\n            remainingEnrollmentsSpeechLengthInSec: json.remainingEnrollmentsSpeechLengthInSec ? parseFloat(json.remainingEnrollmentsSpeechLengthInSec) : 0\r\n        };\r\n    }\r\n}\r\n\r\n/**\r\n * @class VoiceProfileEnrollmentCancellationDetails\r\n */\r\n// tslint:disable-next-line:max-classes-per-file\r\nexport class VoiceProfileEnrollmentCancellationDetails extends CancellationDetailsBase {\r\n\r\n    private constructor(reason: CancellationReason, errorDetails: string, errorCode: CancellationErrorCode) {\r\n        super(reason, errorDetails, errorCode);\r\n    }\r\n\r\n    /**\r\n     * Creates an instance of VoiceProfileEnrollmentCancellationDetails object for the canceled VoiceProfileEnrollmentResult.\r\n     * @member VoiceProfileEnrollmentCancellationDetails.fromResult\r\n     * @function\r\n     * @public\r\n     * @param {VoiceProfileEnrollmentResult} result - The result that was canceled.\r\n     * @returns {VoiceProfileEnrollmentCancellationDetails} The cancellation details object being created.\r\n     */\r\n    public static fromResult(result: VoiceProfileEnrollmentResult): VoiceProfileEnrollmentCancellationDetails {\r\n        const reason = CancellationReason.Error;\r\n        let errorCode: CancellationErrorCode = CancellationErrorCode.NoError;\r\n\r\n        if (!!result.properties) {\r\n            errorCode = (CancellationErrorCode as any)[result.properties.getProperty(CancellationErrorCodePropertyName, CancellationErrorCode[CancellationErrorCode.NoError])];\r\n        }\r\n\r\n        return new VoiceProfileEnrollmentCancellationDetails(reason, result.errorDetails, errorCode);\r\n    }\r\n}\r\n"]}