module Prime
  class Rewards::Resources::Terra < Prime::RewardResource
    field :time, type: :timestamp
    field :validator_address, type: :string, source: :validator
    field :currency, type: :string
    field :numeric, type: :integer
    field :exp, type: :integer

    def token_display
      currency&.slice(1..)&.upcase
    end

    def amount
      numeric.to_d / (10 ** (exp || 0))
    end

    def identifier
      [time.to_i, validator_address, currency].reject(&:blank?).join('-')
    end
  end
end
