<?php
/**
 * Autogenerated by Thrift Compiler (0.16.0)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
use Thrift\Base\TBase;
use Thrift\Type\TType;
use Thrift\Type\TMessageType;
use Thrift\Exception\TException;
use Thrift\Exception\TProtocolException;
use Thrift\Protocol\TProtocol;
use Thrift\Protocol\TBinaryProtocolAccelerated;
use Thrift\Exception\TApplicationException;

class Query
{
    static public $isValidate = false;

    static public $_TSPEC = array(
        1 => array(
            'var' => 'queryId',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        2 => array(
            'var' => 'queryType',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        3 => array(
            'var' => 'queryAttributes',
            'isRequired' => false,
            'type' => TType::MAP,
            'ktype' => TType::STRING,
            'vtype' => TType::STRING,
            'key' => array(
                'type' => TType::STRING,
            ),
            'val' => array(
                'type' => TType::STRING,
                ),
        ),
        4 => array(
            'var' => 'queryCounters',
            'isRequired' => false,
            'type' => TType::MAP,
            'ktype' => TType::STRING,
            'vtype' => TType::I64,
            'key' => array(
                'type' => TType::STRING,
            ),
            'val' => array(
                'type' => TType::I64,
                ),
        ),
        5 => array(
            'var' => 'stageGraph',
            'isRequired' => false,
            'type' => TType::STRUCT,
            'class' => '\Graph',
        ),
        6 => array(
            'var' => 'stageList',
            'isRequired' => false,
            'type' => TType::LST,
            'etype' => TType::STRUCT,
            'elem' => array(
                'type' => TType::STRUCT,
                'class' => '\Stage',
                ),
        ),
        7 => array(
            'var' => 'done',
            'isRequired' => false,
            'type' => TType::BOOL,
        ),
        8 => array(
            'var' => 'started',
            'isRequired' => false,
            'type' => TType::BOOL,
        ),
    );

    /**
     * @var string
     */
    public $queryId = null;
    /**
     * @var string
     */
    public $queryType = null;
    /**
     * @var array
     */
    public $queryAttributes = null;
    /**
     * @var array
     */
    public $queryCounters = null;
    /**
     * @var \Graph
     */
    public $stageGraph = null;
    /**
     * @var \Stage[]
     */
    public $stageList = null;
    /**
     * @var bool
     */
    public $done = null;
    /**
     * @var bool
     */
    public $started = null;

    public function __construct($vals = null)
    {
        if (is_array($vals)) {
            if (isset($vals['queryId'])) {
                $this->queryId = $vals['queryId'];
            }
            if (isset($vals['queryType'])) {
                $this->queryType = $vals['queryType'];
            }
            if (isset($vals['queryAttributes'])) {
                $this->queryAttributes = $vals['queryAttributes'];
            }
            if (isset($vals['queryCounters'])) {
                $this->queryCounters = $vals['queryCounters'];
            }
            if (isset($vals['stageGraph'])) {
                $this->stageGraph = $vals['stageGraph'];
            }
            if (isset($vals['stageList'])) {
                $this->stageList = $vals['stageList'];
            }
            if (isset($vals['done'])) {
                $this->done = $vals['done'];
            }
            if (isset($vals['started'])) {
                $this->started = $vals['started'];
            }
        }
    }

    public function getName()
    {
        return 'Query';
    }


    public function read($input)
    {
        $xfer = 0;
        $fname = null;
        $ftype = 0;
        $fid = 0;
        $xfer += $input->readStructBegin($fname);
        while (true) {
            $xfer += $input->readFieldBegin($fname, $ftype, $fid);
            if ($ftype == TType::STOP) {
                break;
            }
            switch ($fid) {
                case 1:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->queryId);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 2:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->queryType);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 3:
                    if ($ftype == TType::MAP) {
                        $this->queryAttributes = array();
                        $_size89 = 0;
                        $_ktype90 = 0;
                        $_vtype91 = 0;
                        $xfer += $input->readMapBegin($_ktype90, $_vtype91, $_size89);
                        for ($_i93 = 0; $_i93 < $_size89; ++$_i93) {
                            $key94 = '';
                            $val95 = '';
                            $xfer += $input->readString($key94);
                            $xfer += $input->readString($val95);
                            $this->queryAttributes[$key94] = $val95;
                        }
                        $xfer += $input->readMapEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 4:
                    if ($ftype == TType::MAP) {
                        $this->queryCounters = array();
                        $_size96 = 0;
                        $_ktype97 = 0;
                        $_vtype98 = 0;
                        $xfer += $input->readMapBegin($_ktype97, $_vtype98, $_size96);
                        for ($_i100 = 0; $_i100 < $_size96; ++$_i100) {
                            $key101 = '';
                            $val102 = 0;
                            $xfer += $input->readString($key101);
                            $xfer += $input->readI64($val102);
                            $this->queryCounters[$key101] = $val102;
                        }
                        $xfer += $input->readMapEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 5:
                    if ($ftype == TType::STRUCT) {
                        $this->stageGraph = new \Graph();
                        $xfer += $this->stageGraph->read($input);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 6:
                    if ($ftype == TType::LST) {
                        $this->stageList = array();
                        $_size103 = 0;
                        $_etype106 = 0;
                        $xfer += $input->readListBegin($_etype106, $_size103);
                        for ($_i107 = 0; $_i107 < $_size103; ++$_i107) {
                            $elem108 = null;
                            $elem108 = new \Stage();
                            $xfer += $elem108->read($input);
                            $this->stageList []= $elem108;
                        }
                        $xfer += $input->readListEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 7:
                    if ($ftype == TType::BOOL) {
                        $xfer += $input->readBool($this->done);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 8:
                    if ($ftype == TType::BOOL) {
                        $xfer += $input->readBool($this->started);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                default:
                    $xfer += $input->skip($ftype);
                    break;
            }
            $xfer += $input->readFieldEnd();
        }
        $xfer += $input->readStructEnd();
        return $xfer;
    }

    public function write($output)
    {
        $xfer = 0;
        $xfer += $output->writeStructBegin('Query');
        if ($this->queryId !== null) {
            $xfer += $output->writeFieldBegin('queryId', TType::STRING, 1);
            $xfer += $output->writeString($this->queryId);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->queryType !== null) {
            $xfer += $output->writeFieldBegin('queryType', TType::STRING, 2);
            $xfer += $output->writeString($this->queryType);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->queryAttributes !== null) {
            if (!is_array($this->queryAttributes)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('queryAttributes', TType::MAP, 3);
            $output->writeMapBegin(TType::STRING, TType::STRING, count($this->queryAttributes));
            foreach ($this->queryAttributes as $kiter109 => $viter110) {
                $xfer += $output->writeString($kiter109);
                $xfer += $output->writeString($viter110);
            }
            $output->writeMapEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->queryCounters !== null) {
            if (!is_array($this->queryCounters)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('queryCounters', TType::MAP, 4);
            $output->writeMapBegin(TType::STRING, TType::I64, count($this->queryCounters));
            foreach ($this->queryCounters as $kiter111 => $viter112) {
                $xfer += $output->writeString($kiter111);
                $xfer += $output->writeI64($viter112);
            }
            $output->writeMapEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->stageGraph !== null) {
            if (!is_object($this->stageGraph)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('stageGraph', TType::STRUCT, 5);
            $xfer += $this->stageGraph->write($output);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->stageList !== null) {
            if (!is_array($this->stageList)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('stageList', TType::LST, 6);
            $output->writeListBegin(TType::STRUCT, count($this->stageList));
            foreach ($this->stageList as $iter113) {
                $xfer += $iter113->write($output);
            }
            $output->writeListEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->done !== null) {
            $xfer += $output->writeFieldBegin('done', TType::BOOL, 7);
            $xfer += $output->writeBool($this->done);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->started !== null) {
            $xfer += $output->writeFieldBegin('started', TType::BOOL, 8);
            $xfer += $output->writeBool($this->started);
            $xfer += $output->writeFieldEnd();
        }
        $xfer += $output->writeFieldStop();
        $xfer += $output->writeStructEnd();
        return $xfer;
    }
}
