<?php
/**
 * Created by PhpStorm.
 * User: steven
 * Date: 7/26/19
 * Time: 2:35 PM
 */

namespace Hilco\XMLBuilder;

use Hilco\XMLBuilder\XMLUtility;
class RateShopUtility extends XMLUtility
{
    public function __construct($attributes)
    {
        parent::__construct($attributes);
    }


    public function getRates(){
        $rateValues = [];
        if($this->simpleXML == null){
            $this->simpleXML = simplexml_load_string($this->xml);
        }
        $simpleXML = $this->simpleXML;
        if ($simpleXML != null) {
            $Rates = $simpleXML->RateShop->Rate;
            if (empty($Rates)) return $rateValues;
            $rateValues = XMLUtility::retrieveStackValues($Rates, [], [
                'carrier_name' => ['Carrier'],
                'api_code' => ['CarrierServiceCode'],
                'carrier_desc' => ['Service'],
                'rate' => ['PublishedRate'],
                'discounted_rate' => ['DiscountedRate'],
                'delivery_datetime' => ['EstmatedTime'], // Yes, it's mispelled like that at least as of this time (7/26/2019: 3:13 PM)
                'rate_type' => ['RateType'], // multiple USPS Rate options can be returned now, differentiated by RateType
            ]);
        }

        return $rateValues;
    }
    


}