# frozen_string_literal: true require 'time' require 'truelayer/base_model' require 'truelayer/running_balance' require 'truelayer/transaction_meta' module Truelayer class Transaction < BaseModel attributes :transaction_id, :normalised_provider_transaction_id, :provider_transaction_id, :timestamp, :description, :amount, :currency, :transaction_type, :transaction_category, :transaction_classification, :merchant_name, :running_balance, :meta def self.build(json:) super.tap do |record| record.running_balance = RunningBalance.build(json: (record.running_balance || {})) record.meta = TransactionMeta.build(json: (record.meta || {})) record.timestamp = Time.parse(record.timestamp) if record.timestamp end end end end