<?php

class Tracking {

    /**
     *
     * @global type $SETTINGS
     * @param string $code
     * @return \TrackingInfo
     * @throws TrackingException
     */
    public static function track(string $code, string $carrier = ""): TrackingInfo {

        $barcode = new TrackingBarcode($code);
        if (!empty($carrier)) {
            $carriercode = Carriers::getCarrierCode($carrier);
        } else {
            $carriercode = $barcode->getCarrier();
        }

        switch ($carriercode) {
            case "usps_gsbarcode":
                return Tracking_USPS_gsbarcode::track($code);
            case "ups_mi_datamatrix":
                return Tracking_UPS_MailInnovations_DataMatrix::track($code);
            case "fedex_pdf417":
                return Tracking_FedEx_PDF417::track($code);
            case "helena_express":
                return Tracking_HelenaExpress::track($barcode->getSanitized());
            case "usps":
                return Tracking_USPS::track($barcode->getSanitized());
            case "ups":
                return Tracking_UPS::track($barcode->getSanitized());
            case "fedex":
                return Tracking_FedEx::track($barcode->getSanitized());
            default:
                return Tracking_EasyPost::track($barcode->getSanitized());
                //return Tracking_Shippo::track($barcode->getSanitized());
        }
    }

}
