<?php
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# source: google/appengine/v1/service.proto

namespace Google\Cloud\AppEngine\V1\TrafficSplit;

use UnexpectedValueException;

/**
 * Available sharding mechanisms.
 *
 * Protobuf type <code>google.appengine.v1.TrafficSplit.ShardBy</code>
 */
class ShardBy
{
    /**
     * Diversion method unspecified.
     *
     * Generated from protobuf enum <code>UNSPECIFIED = 0;</code>
     */
    const UNSPECIFIED = 0;
    /**
     * Diversion based on a specially named cookie, "GOOGAPPUID." The cookie
     * must be set by the application itself or no diversion will occur.
     *
     * Generated from protobuf enum <code>COOKIE = 1;</code>
     */
    const COOKIE = 1;
    /**
     * Diversion based on applying the modulus operation to a fingerprint
     * of the IP address.
     *
     * Generated from protobuf enum <code>IP = 2;</code>
     */
    const IP = 2;
    /**
     * Diversion based on weighted random assignment. An incoming request is
     * randomly routed to a version in the traffic split, with probability
     * proportional to the version's traffic share.
     *
     * Generated from protobuf enum <code>RANDOM = 3;</code>
     */
    const RANDOM = 3;

    private static $valueToName = [
        self::UNSPECIFIED => 'UNSPECIFIED',
        self::COOKIE => 'COOKIE',
        self::IP => 'IP',
        self::RANDOM => 'RANDOM',
    ];

    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);
    }
}

// Adding a class alias for backwards compatibility with the previous class name.
class_alias(ShardBy::class, \Google\Cloud\AppEngine\V1\TrafficSplit_ShardBy::class);

