require_relative "base"
require_relative "validity_check"

module Conduit::Driver::Telispire
  class QueryDeviceInfo::Parser < Parser::Base
    include ValidityCheck

    attribute :vendor_id
    attribute :request_type
    attribute :order_type
    attribute :reference_number
    attribute :device_id
    attribute :is_lost_or_stolen
    attribute :mode
    attribute :model

    attribute :manufacturer do
      content_for "//make"
    end

    attribute :return_url do
      content_for "//returnURL"
    end

    attribute :is_in_dmd do
      content_for "//isInDMD"
    end

    attribute :is_pib_lock do
      content_for "//isPIBLock"
    end

    attribute :success do
      is_valid == "Y"
    end

    attribute :device_valid do
      is_valid == "Y"
    end

    attribute :lte_device do
      mode == "4G"
    end

    attribute :requires_proxy_transfer do
      return_message == "DISCOUNT_1_ACCESS" ||
        return_message == "DISCOUNT_2_ACCESS"
    end

    attribute :message do
      messages = []
      messages << "MEID is invalid" if is_valid == "N"
      messages << "Device is lost or stolen" if is_lost_or_stolen == "Y"
      messages << "Device is locked" if is_pib_lock == "Y" && is_in_dmd != "Y"
      messages << "Device can be activated" if messages.empty?
      messages.join ". "
    end
  end
end
