<?php
namespace Fusio\Impl\Worker\Generated;

/**
 * Autogenerated by Thrift Compiler (0.14.2)
 *
 * 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 Result
{
    static public $isValidate = false;

    static public $_TSPEC = array(
        1 => array(
            'var' => 'response',
            'isRequired' => false,
            'type' => TType::STRUCT,
            'class' => '\Fusio\Impl\Worker\Generated\Response',
        ),
        2 => array(
            'var' => 'events',
            'isRequired' => false,
            'type' => TType::LST,
            'etype' => TType::STRUCT,
            'elem' => array(
                'type' => TType::STRUCT,
                'class' => '\Fusio\Impl\Worker\Generated\Event',
                ),
        ),
        3 => array(
            'var' => 'logs',
            'isRequired' => false,
            'type' => TType::LST,
            'etype' => TType::STRUCT,
            'elem' => array(
                'type' => TType::STRUCT,
                'class' => '\Fusio\Impl\Worker\Generated\Log',
                ),
        ),
    );

    /**
     * @var \Fusio\Impl\Worker\Generated\Response
     */
    public $response = null;
    /**
     * @var \Fusio\Impl\Worker\Generated\Event[]
     */
    public $events = null;
    /**
     * @var \Fusio\Impl\Worker\Generated\Log[]
     */
    public $logs = null;

    public function __construct($vals = null)
    {
        if (is_array($vals)) {
            if (isset($vals['response'])) {
                $this->response = $vals['response'];
            }
            if (isset($vals['events'])) {
                $this->events = $vals['events'];
            }
            if (isset($vals['logs'])) {
                $this->logs = $vals['logs'];
            }
        }
    }

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


    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::STRUCT) {
                        $this->response = new \Fusio\Impl\Worker\Generated\Response();
                        $xfer += $this->response->read($input);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 2:
                    if ($ftype == TType::LST) {
                        $this->events = array();
                        $_size50 = 0;
                        $_etype53 = 0;
                        $xfer += $input->readListBegin($_etype53, $_size50);
                        for ($_i54 = 0; $_i54 < $_size50; ++$_i54) {
                            $elem55 = null;
                            $elem55 = new \Fusio\Impl\Worker\Generated\Event();
                            $xfer += $elem55->read($input);
                            $this->events []= $elem55;
                        }
                        $xfer += $input->readListEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 3:
                    if ($ftype == TType::LST) {
                        $this->logs = array();
                        $_size56 = 0;
                        $_etype59 = 0;
                        $xfer += $input->readListBegin($_etype59, $_size56);
                        for ($_i60 = 0; $_i60 < $_size56; ++$_i60) {
                            $elem61 = null;
                            $elem61 = new \Fusio\Impl\Worker\Generated\Log();
                            $xfer += $elem61->read($input);
                            $this->logs []= $elem61;
                        }
                        $xfer += $input->readListEnd();
                    } 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('Result');
        if ($this->response !== null) {
            if (!is_object($this->response)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('response', TType::STRUCT, 1);
            $xfer += $this->response->write($output);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->events !== null) {
            if (!is_array($this->events)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('events', TType::LST, 2);
            $output->writeListBegin(TType::STRUCT, count($this->events));
            foreach ($this->events as $iter62) {
                $xfer += $iter62->write($output);
            }
            $output->writeListEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->logs !== null) {
            if (!is_array($this->logs)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('logs', TType::LST, 3);
            $output->writeListBegin(TType::STRUCT, count($this->logs));
            foreach ($this->logs as $iter63) {
                $xfer += $iter63->write($output);
            }
            $output->writeListEnd();
            $xfer += $output->writeFieldEnd();
        }
        $xfer += $output->writeFieldStop();
        $xfer += $output->writeStructEnd();
        return $xfer;
    }
}
