<?php

require_once dirname(__FILE__) . '/../../lib/AbstractPhoneModel.php';

class Ergophone extends AbstractPhoneModel
{

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

    public function validateFirmwareFile($filename, $fileTmpPath, &$errorText)
    {
        return true; // FIXME
    }

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

    public static function getFunctionPlaceholders()
    {
        return array(
            '0' => "---",
            '1' => 'ZielWahl',
            '2' => "Notruf",
//             //TEST 
//             '2'=>'Licht_an',
//             '3'=>'Licht_aus',
        );
    }

    public static function getFunctions($translated = true)
    {
        // FIXME ???
        if ($translated) {
            $functions = array();
            foreach (self::getFunctionPlaceholders() as $key => $value) {
                $functions[$key] = __($value);
            }
            return $functions;
        } else {
            return self::getFunctionPlaceholders();
        }
    }

    public function getAvailableKeys($level)
    {
        $phones = $this->getSupportedPhoneModels();
        if (!array_key_exists($this->mPhoneModelName, $phones)) {
            return array();
        }

        $phone = $phones[$this->mPhoneModelName];
        $ret = array();

        if ($level == "" || $level == "fpk") {

            $button = new PhoneKey();
            $button->name = "Notruftaste";
            $button->phone = $this->mPhoneModelName;
            $button->function = '';
            $button->level = 'fpk';
            $button->key_idx = 0;
            $button->availableFunctions = $this->getFunctions();

            $ret[$button->name] = $button;

            for ($i = 1; $i <= $phone->getKeys(); $i++) {
                $button = new PhoneKey();
                $button->name = "FKey_" . $i;
                $button->phone = $this->mPhoneModelName;
                $button->function = '';
                $button->level = 'fpk';
                $button->key_idx = $i;
                $button->availableFunctions = $this->getFunctions();

                $ret[$button->name] = $button;
            }
        }
        return $ret;
    }

    public function getAvailableKeyLevels()
    {
        $phones = $this->getSupportedPhoneModels();
        if (!array_key_exists($this->mPhoneModelName, $phones)) {
            return array();
        }
        $phone = $phones[$this->mPhoneModelName];

        $keyLevels = array();

        if ($phone->getKeys() != 0) {
            $lineKeyLevel = array();
            $lineKeyLevel["level"] = "fpk";
            $lineKeyLevel["name"] = "SIEMENS_KEYLEVEL_FPK_NAME";
            $lineKeyLevel["descr"] = "SIEMENS_KEYLEVEL_FPK_DESCR";
            $keyLevels[] = $lineKeyLevel;
        }
        return $keyLevels;
    }

    public function supportsLogoDeployment()
    {
        //FIXME
        return false;
    }

    public function supportsScreenSaverDeployment()
    {
        //FIXME ???
        return false;
    }

    public static function getSupportedPhoneModels()
    {
        $models = array();
        
        // FIXME second "ergoS501" should be a useragent
        $tmp = new Ergophone(Ergophone::getManufactorName(), "ergoS501", "ergoS501");
        $tmp->setPhoneModelNameHumanReadable("Ergophone S510 IP");
        $tmp->setKeys(7);
        $tmp->setLineKeys(0);
        $models[$tmp->getPhoneModelName()] = $tmp;

        return $models;
    }
}
