import type { RouteLocation } from 'vue-router'
import { ApiClient } from './base'
import { getSelectedProfile } from './profile'

export interface BalanceTimeSeriesAnalytics {
  accounts: AccountBalanceTimeSeries[]
  totals: TotalBalanceTimeSeries[]
}

export interface AccountBalanceTimeSeries {
  accountId: number
  currencyCode: string
  balanceTimeSeries: BalanceSnapshot[]
}

export interface TotalBalanceTimeSeries {
  currencyCode: string
  balanceTimeSeries: BalanceSnapshot[]
}

export interface BalanceSnapshot {
  balance: number
  timestamp: string
}

export class AnalyticsApiClient extends ApiClient {
  readonly profileName: string
  readonly path: string

  constructor(route: RouteLocation) {
    super()
    this.profileName = getSelectedProfile(route)
    this.path = `/profiles/${this.profileName}/analytics`
  }

  getBalanceTimeSeries(): Promise<BalanceTimeSeriesAnalytics> {
    return super.getJson(this.path + '/balance-time-series')
  }
}
