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

namespace Google\Cloud\Spanner\V1;

use UnexpectedValueException;

/**
 * `TypeCode` is used as part of [Type][google.spanner.v1.Type] to
 * indicate the type of a Cloud Spanner value.
 * Each legal value of a type can be encoded to or decoded from a JSON
 * value, using the encodings described below. All Cloud Spanner values can
 * be `null`, regardless of type; `null`s are always encoded as a JSON
 * `null`.
 *
 * Protobuf type <code>google.spanner.v1.TypeCode</code>
 */
class TypeCode
{
    /**
     * Not specified.
     *
     * Generated from protobuf enum <code>TYPE_CODE_UNSPECIFIED = 0;</code>
     */
    const TYPE_CODE_UNSPECIFIED = 0;
    /**
     * Encoded as JSON `true` or `false`.
     *
     * Generated from protobuf enum <code>BOOL = 1;</code>
     */
    const BOOL = 1;
    /**
     * Encoded as `string`, in decimal format.
     *
     * Generated from protobuf enum <code>INT64 = 2;</code>
     */
    const INT64 = 2;
    /**
     * Encoded as `number`, or the strings `"NaN"`, `"Infinity"`, or
     * `"-Infinity"`.
     *
     * Generated from protobuf enum <code>FLOAT64 = 3;</code>
     */
    const FLOAT64 = 3;
    /**
     * Encoded as `string` in RFC 3339 timestamp format. The time zone
     * must be present, and must be `"Z"`.
     * If the schema has the column option
     * `allow_commit_timestamp=true`, the placeholder string
     * `"spanner.commit_timestamp()"` can be used to instruct the system
     * to insert the commit timestamp associated with the transaction
     * commit.
     *
     * Generated from protobuf enum <code>TIMESTAMP = 4;</code>
     */
    const TIMESTAMP = 4;
    /**
     * Encoded as `string` in RFC 3339 date format.
     *
     * Generated from protobuf enum <code>DATE = 5;</code>
     */
    const DATE = 5;
    /**
     * Encoded as `string`.
     *
     * Generated from protobuf enum <code>STRING = 6;</code>
     */
    const STRING = 6;
    /**
     * Encoded as a base64-encoded `string`, as described in RFC 4648,
     * section 4.
     *
     * Generated from protobuf enum <code>BYTES = 7;</code>
     */
    const BYTES = 7;
    /**
     * Encoded as `list`, where the list elements are represented
     * according to
     * [array_element_type][google.spanner.v1.Type.array_element_type].
     *
     * Generated from protobuf enum <code>ARRAY = 8;</code>
     */
    const PBARRAY = 8;
    /**
     * Encoded as `list`, where list element `i` is represented according
     * to [struct_type.fields[i]][google.spanner.v1.StructType.fields].
     *
     * Generated from protobuf enum <code>STRUCT = 9;</code>
     */
    const STRUCT = 9;

    private static $valueToName = [
        self::TYPE_CODE_UNSPECIFIED => 'TYPE_CODE_UNSPECIFIED',
        self::BOOL => 'BOOL',
        self::INT64 => 'INT64',
        self::FLOAT64 => 'FLOAT64',
        self::TIMESTAMP => 'TIMESTAMP',
        self::DATE => 'DATE',
        self::STRING => 'STRING',
        self::BYTES => 'BYTES',
        self::PBARRAY => 'PBARRAY',
        self::STRUCT => 'STRUCT',
    ];

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

