import { TransitionOption, TransitionInfoResponse } from '../types/transition'; import { BillingAccount } from '../types/subscription'; export class TransitionInfo { public subscriptionNumber: string; public type: string; public typeReason: string; public options: Array; public billingAccount: BillingAccount; public productName: string; public currentTerm: string; public currentPrice: number; public trialPrice?: number; public currency: string; public symbol: string; /** * Transition Info * @param transitionData mapped transition info data. */ constructor (transitionData: TransitionInfoResponse) { this.subscriptionNumber = transitionData.subscriptionNumber; this.type = transitionData.upgradeType; this.typeReason = transitionData.upgradeTypeReason; this.options = transitionData.upgradeOptions; this.billingAccount = transitionData.billingAccount; this.productName = transitionData.productName; this.currentTerm = transitionData.currentTerm; this.currentPrice = transitionData.currentPrice; this.trialPrice = transitionData.trialPrice; this.currency = transitionData.currency; this.symbol = transitionData.symbol; } /** * Get whether the user has any potential transition options * @returns whether the user has any potential transition options */ hasOptions(): boolean { return !!this.options && this.options.length > 0; } /** * Find a specific transition option for a given term. * @param term The ISO8601 Duration code to search the transition options for. * @returns The found transition option or undefined. */ findMatchingTermOption(term: string): TransitionOption | undefined { return this.options.find((opt: TransitionOption) => opt.term === term); } }