<?php

require_once dirname(__FILE__) . '/../../lib/phoneprovisioning.php';
require_once dirname(__FILE__) . '/../tiptel-33xx/Tiptel33xx.php';
require_once dirname(__FILE__) . '/../htek/provisioning.php';

class Tiptel33xxPhoneProvisioning extends HtekPhoneProvisioning
{

    const LOG_TAG = 'tiptel-33xx-dls';

    protected function checkUserAgent($ua)
    {
        Log::d("Requested Provisioning " . $ua, self::LOG_TAG);
        $ua = str_replace("tiptel tiptel", "tiptel", strToLower($ua));
        $ua_parts = explode(' ', $ua);
        $manufactorName = strToLower(@$ua_parts[0]);
        $phoneModelName = @$ua_parts[1];

        if ($manufactorName === 'tiptel' && startsWith($phoneModelName, '33')) {
            $found = false;
            $agentName = $manufactorName . $phoneModelName;
            foreach (Tiptel33xx::getSupportedPhoneModels() as $model) {
                if ($model->getUserAgent() == $agentName) {
                    $this->setCurrentPhoneModel($model);
                    $found = true;
                    break;
                }
            }

            $firmware = @$ua_parts[2];
            # find out the firmware version of the phone
            $fw_vers = (preg_match('/(\d+\.\d+\.\d+\.\d+)/', $firmware, $m)) ? $m[1] : '0.0.0.0';
            $fw_vers_nrml = Tiptel33xx::tiptel_normalize_version($fw_vers);
            $this->setCurrentFirmwareVersion($fw_vers_nrml);
            return $found;
        }
        return parent::checkUserAgent($ua);
    }

    protected function getFirmwareServerPath($Phone)
    {
        return "";
    }
}
