import { Id } from './types' ; import { Period } from './period' ; import { Category } from './category' ; import { BudgetDefinition } from './budgetDefinition' ; export class Budget { id ? : string | number ; accountId ? : string | number ; period ! : Period ; categoryId ? : string ; category ? : Category ; maxExpenses = 0 ; currentExpenses = 0 ; get left ( ) : number { return this . maxExpenses - this . currentExpenses ; } get leftPercentage ( ) : string { return 100 * this . currentExpenses / this . maxExpenses + '%' ; } static build ( input ) { const budget = new Budget ( ) ; return Object . assign ( budget , input ) ; } static buildFromJson ( json ) { const budget = new Budget ( ) ; return Object . assign ( budget , json ) ; } static buildFromDefinition ( accountId , period , definition ) { const budget = new Budget ( ) ; budget . accountId = accountId ; budget . period = period ; budget . maxExpenses = definition . maxExpenses ; budget . category = definition . category ; return budget ; } } export interface BudgetInput { id ? : string | number ; accountId ? : string | number ; period ? : Period ; categoryId ? : string ; category ? : Category ; currentExpenses ? : number ; maxExpenses ? : number ; }