<?php
 
 
 

namespace PhpWA\Protocol\Proto\ClientPayload;

use UnexpectedValueException;




class ConnectReason
{
    


    const PUSH = 0;
    


    const USER_ACTIVATED = 1;
    


    const SCHEDULED = 2;
    


    const ERROR_RECONNECT = 3;
    


    const NETWORK_SWITCH = 4;
    


    const PING_RECONNECT = 5;
    


    const UNKNOWN = 6;

    private static $valueToName = [
        self::PUSH => 'PUSH',
        self::USER_ACTIVATED => 'USER_ACTIVATED',
        self::SCHEDULED => 'SCHEDULED',
        self::ERROR_RECONNECT => 'ERROR_RECONNECT',
        self::NETWORK_SWITCH => 'NETWORK_SWITCH',
        self::PING_RECONNECT => 'PING_RECONNECT',
        self::UNKNOWN => 'UNKNOWN',
    ];

    public static function name($value)
    {
        if (!isset(self::$valueToName[$value])) {
            throw new UnexpectedValueException(sprintf(
                    'Enum %s has no name defined for value %s', __CLASS__, $value));
        }
        return self::$valueToName[$value];
    }


    public static function value($name)
    {
        $const = __CLASS__ . '::' . strtoupper($name);
        if (!defined($const)) {
            throw new UnexpectedValueException(sprintf(
                    'Enum %s has no value defined for name %s', __CLASS__, $name));
        }
        return constant($const);
    }
}

