<?php

class AbstractPhoneModel
{

    private $mLineKeys = 0;
    private $mKeys = 0;

    private $mExtKey = 0;
    private $mExtModule = 0;

    private $mUsbExtKey = 0;
    private $mUsbExtModule = 0;

    protected $mManufactorName = null;
    protected $mPhoneModelName = null;
    protected $mPhoneModelNameHuman = null;
    protected $mPhoneUserAgent = null;

    public function __construct($manufactorName = "", $phoneModelName = "", $phoneUserAgent = "")
    {
        $this->mManufactorName = $manufactorName;
        $this->mPhoneModelName = $phoneModelName;
        $this->mPhoneUserAgent = $phoneUserAgent;
    }

    public function getPhoneModelName()
    {
        return $this->mPhoneModelName;
    }

    public function getPhoneModelNameHumanReadable()
    {
        if ($this->mPhoneModelNameHuman == null) {
            return $this->mPhoneModelName;
        } else {
            return $this->mPhoneModelNameHuman;
        }
    }

    protected function endsWith($haystack, $needle, $case = true)
    {
        if ($case) {
            return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0);
        }
        return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0);
    }

    public function setPhoneModelNameHumanReadable($name)
    {
        $this->mPhoneModelNameHuman = $name;
    }

    public static function getManufactorName()
    {
        return "";
    }

    public function getUserAgent()
    {
        return $this->mPhoneUserAgent;
    }

    public function setLineKeys($keys)
    {
        $this->mLineKeys = $keys;
    }

    public function setKeys($keys)
    {
        $this->mKeys = $keys;
    }

    public function setExtKeys($keys)
    {
        $this->mExtKey = $keys;
    }

    public function setExtModules($keys)
    {
        $this->mExtModule = $keys;
    }

    public function setUsbExtKeys($keys)
    {
        $this->mUsbExtKey = $keys;
    }

    public function setUsbExtModules($keys)
    {
        $this->mUsbExtModule = $keys;
    }

    public function getLineKeys()
    {
        return $this->mLineKeys;
    }

    public function getKeys()
    {
        return $this->mKeys;
    }

    public function getExtKeys()
    {
        return $this->mExtKey;
    }

    public function getExtModules()
    {
        return $this->mExtModule;
    }

    public function getUsbExtKeys()
    {
        return $this->mUsbExtKey;
    }

    public function getUsbExtModules()
    {
        return $this->mUsbExtModule;
    }

    // REIMPLEMENT THESE FUNCTIONS IN SUBCLASSES! {

    public function validateFirmwareFile($filename, $fileTmpPath, &$errorText)
    {
        $errorText = __("not implemented in " . __CLASS__);
        return false;
    }

    public function getAvailableKeys($level)
    {
        return array();
    }

    public function getAvailableKeyLevels()
    {
        return array();
    }

    public function getUploadableFiles()
    {
        return array();
    }

    public function getCallServiceURL($to, $id, $clip)
    {
        return '';
    }
    // } REIMPLEMENT THESE FUNCTIONS IN SUBCLASSES!
}
