# frozen_string_literal: true

module Faker
  class Finreach < Base
    class << self
      def transaction
        transaction = {
          id: id,
          amount: amount,
          currency: Faker::Currency.code,
          bookingDate: created_at,
          bookingText: Faker::Hipster.sentence,
          counter_account: counter_account,
          name: Faker::Name.first_name + ' ' + Faker::Name.last_name,
          purpose: Faker::Hipster.sentence,
          valueDate: created_at,
          accountId: id,
          createdAt: created_at,
          updatedAt: created_at,
          type: 'transfer_received',
          categories: categories
        }
        transaction
      end

      private

      def id
        Faker::Alphanumeric.alpha(number: 37)
      end

      def created_at
        Faker::Date.between(from: '2019-01-01', to: ::Date.today).strftime('%Y-%m-%dT%H:%M:%S.%LZ')
      end

      def counter_account
        {
          bankName: 'DKB',
          bankCode: 'BYM',
          bic: Faker::Bank.swift_bic,
          iban: Faker::Bank.iban
        }
      end

      def booking_type
        fetch('solaris.booking_type')
      end

      def amount
        digits = rand(1...6)
        dec_places = 10**digits
        seed_value = rand
        cash_value = (seed_value * dec_places).round(0)
        cash_value
      end

      def solaris_iban
        prefix = 'DE231101010000'
        suffix = Faker::Number.number(digits: 10)
        prefix + suffix.to_s
      end

      def sepa_return_code
        fetch('solaris.sepa_return_code')
      end

      def categories
        categories = []
        category = {}
        category[:id] = Faker::Number.number(digits: 3)
        category[:name] = Faker::Color.color_name
        category[:parent] = {}
        categories.push(category)
        categories
      end
    end
  end
end
