<?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 Execute
{
    static public $isValidate = false;

    static public $_TSPEC = array(
        1 => array(
            'var' => 'action',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        2 => array(
            'var' => 'request',
            'isRequired' => false,
            'type' => TType::STRUCT,
            'class' => '\Fusio\Impl\Worker\Generated\Request',
        ),
        3 => array(
            'var' => 'context',
            'isRequired' => false,
            'type' => TType::STRUCT,
            'class' => '\Fusio\Impl\Worker\Generated\Context',
        ),
    );

    /**
     * @var string
     */
    public $action = null;
    /**
     * @var \Fusio\Impl\Worker\Generated\Request
     */
    public $request = null;
    /**
     * @var \Fusio\Impl\Worker\Generated\Context
     */
    public $context = null;

    public function __construct($vals = null)
    {
        if (is_array($vals)) {
            if (isset($vals['action'])) {
                $this->action = $vals['action'];
            }
            if (isset($vals['request'])) {
                $this->request = $vals['request'];
            }
            if (isset($vals['context'])) {
                $this->context = $vals['context'];
            }
        }
    }

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


    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->action);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 2:
                    if ($ftype == TType::STRUCT) {
                        $this->request = new \Fusio\Impl\Worker\Generated\Request();
                        $xfer += $this->request->read($input);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 3:
                    if ($ftype == TType::STRUCT) {
                        $this->context = new \Fusio\Impl\Worker\Generated\Context();
                        $xfer += $this->context->read($input);
                    } 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('Execute');
        if ($this->action !== null) {
            $xfer += $output->writeFieldBegin('action', TType::STRING, 1);
            $xfer += $output->writeString($this->action);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->request !== null) {
            if (!is_object($this->request)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('request', TType::STRUCT, 2);
            $xfer += $this->request->write($output);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->context !== null) {
            if (!is_object($this->context)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('context', TType::STRUCT, 3);
            $xfer += $this->context->write($output);
            $xfer += $output->writeFieldEnd();
        }
        $xfer += $output->writeFieldStop();
        $xfer += $output->writeStructEnd();
        return $xfer;
    }
}
