<?php
namespace metastore;

/**
 * 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 WMFullResourcePlan
{
    static public $isValidate = false;

    static public $_TSPEC = array(
        1 => array(
            'var' => 'plan',
            'isRequired' => true,
            'type' => TType::STRUCT,
            'class' => '\metastore\WMResourcePlan',
        ),
        2 => array(
            'var' => 'pools',
            'isRequired' => true,
            'type' => TType::LST,
            'etype' => TType::STRUCT,
            'elem' => array(
                'type' => TType::STRUCT,
                'class' => '\metastore\WMPool',
                ),
        ),
        3 => array(
            'var' => 'mappings',
            'isRequired' => false,
            'type' => TType::LST,
            'etype' => TType::STRUCT,
            'elem' => array(
                'type' => TType::STRUCT,
                'class' => '\metastore\WMMapping',
                ),
        ),
        4 => array(
            'var' => 'triggers',
            'isRequired' => false,
            'type' => TType::LST,
            'etype' => TType::STRUCT,
            'elem' => array(
                'type' => TType::STRUCT,
                'class' => '\metastore\WMTrigger',
                ),
        ),
        5 => array(
            'var' => 'poolTriggers',
            'isRequired' => false,
            'type' => TType::LST,
            'etype' => TType::STRUCT,
            'elem' => array(
                'type' => TType::STRUCT,
                'class' => '\metastore\WMPoolTrigger',
                ),
        ),
    );

    /**
     * @var \metastore\WMResourcePlan
     */
    public $plan = null;
    /**
     * @var \metastore\WMPool[]
     */
    public $pools = null;
    /**
     * @var \metastore\WMMapping[]
     */
    public $mappings = null;
    /**
     * @var \metastore\WMTrigger[]
     */
    public $triggers = null;
    /**
     * @var \metastore\WMPoolTrigger[]
     */
    public $poolTriggers = null;

    public function __construct($vals = null)
    {
        if (is_array($vals)) {
            if (isset($vals['plan'])) {
                $this->plan = $vals['plan'];
            }
            if (isset($vals['pools'])) {
                $this->pools = $vals['pools'];
            }
            if (isset($vals['mappings'])) {
                $this->mappings = $vals['mappings'];
            }
            if (isset($vals['triggers'])) {
                $this->triggers = $vals['triggers'];
            }
            if (isset($vals['poolTriggers'])) {
                $this->poolTriggers = $vals['poolTriggers'];
            }
        }
    }

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


    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->plan = new \metastore\WMResourcePlan();
                        $xfer += $this->plan->read($input);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 2:
                    if ($ftype == TType::LST) {
                        $this->pools = array();
                        $_size742 = 0;
                        $_etype745 = 0;
                        $xfer += $input->readListBegin($_etype745, $_size742);
                        for ($_i746 = 0; $_i746 < $_size742; ++$_i746) {
                            $elem747 = null;
                            $elem747 = new \metastore\WMPool();
                            $xfer += $elem747->read($input);
                            $this->pools []= $elem747;
                        }
                        $xfer += $input->readListEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 3:
                    if ($ftype == TType::LST) {
                        $this->mappings = array();
                        $_size748 = 0;
                        $_etype751 = 0;
                        $xfer += $input->readListBegin($_etype751, $_size748);
                        for ($_i752 = 0; $_i752 < $_size748; ++$_i752) {
                            $elem753 = null;
                            $elem753 = new \metastore\WMMapping();
                            $xfer += $elem753->read($input);
                            $this->mappings []= $elem753;
                        }
                        $xfer += $input->readListEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 4:
                    if ($ftype == TType::LST) {
                        $this->triggers = array();
                        $_size754 = 0;
                        $_etype757 = 0;
                        $xfer += $input->readListBegin($_etype757, $_size754);
                        for ($_i758 = 0; $_i758 < $_size754; ++$_i758) {
                            $elem759 = null;
                            $elem759 = new \metastore\WMTrigger();
                            $xfer += $elem759->read($input);
                            $this->triggers []= $elem759;
                        }
                        $xfer += $input->readListEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 5:
                    if ($ftype == TType::LST) {
                        $this->poolTriggers = array();
                        $_size760 = 0;
                        $_etype763 = 0;
                        $xfer += $input->readListBegin($_etype763, $_size760);
                        for ($_i764 = 0; $_i764 < $_size760; ++$_i764) {
                            $elem765 = null;
                            $elem765 = new \metastore\WMPoolTrigger();
                            $xfer += $elem765->read($input);
                            $this->poolTriggers []= $elem765;
                        }
                        $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('WMFullResourcePlan');
        if ($this->plan !== null) {
            if (!is_object($this->plan)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('plan', TType::STRUCT, 1);
            $xfer += $this->plan->write($output);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->pools !== null) {
            if (!is_array($this->pools)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('pools', TType::LST, 2);
            $output->writeListBegin(TType::STRUCT, count($this->pools));
            foreach ($this->pools as $iter766) {
                $xfer += $iter766->write($output);
            }
            $output->writeListEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->mappings !== null) {
            if (!is_array($this->mappings)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('mappings', TType::LST, 3);
            $output->writeListBegin(TType::STRUCT, count($this->mappings));
            foreach ($this->mappings as $iter767) {
                $xfer += $iter767->write($output);
            }
            $output->writeListEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->triggers !== null) {
            if (!is_array($this->triggers)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('triggers', TType::LST, 4);
            $output->writeListBegin(TType::STRUCT, count($this->triggers));
            foreach ($this->triggers as $iter768) {
                $xfer += $iter768->write($output);
            }
            $output->writeListEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->poolTriggers !== null) {
            if (!is_array($this->poolTriggers)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('poolTriggers', TType::LST, 5);
            $output->writeListBegin(TType::STRUCT, count($this->poolTriggers));
            foreach ($this->poolTriggers as $iter769) {
                $xfer += $iter769->write($output);
            }
            $output->writeListEnd();
            $xfer += $output->writeFieldEnd();
        }
        $xfer += $output->writeFieldStop();
        $xfer += $output->writeStructEnd();
        return $xfer;
    }
}
