<?php

class Tracking_FedEx_PDF417 {

    /**
     *
     * @global type $SETTINGS
     * @param string $code
     * @return \TrackingInfo
     * @throws TrackingException
     */
    public static function track(string $code): TrackingInfo {
        $codeparts = preg_split("/(\\x1D|\\x1E)/", $code);

        $realcode = $codeparts[5];

        $info = Tracking::track($realcode, "fedex");

        // Set detailed destination address from code data
        $to = $info->getTo();
        if (is_null($to)) {
            $to = new Location();
        }
        $to->street = $codeparts[13];
        $to->city = $codeparts[14];
        $to->state = $codeparts[15];
        $to->country = (new League\ISO3166\ISO3166)->numeric($codeparts[3])['alpha2'];
        $info->setTo($to);

        return $info;
    }

}
