<?php
/**
 * Autogenerated by Thrift Compiler (0.12.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 ChatSession
{
    static public $isValidate = false;

    static public $_TSPEC = array(
        1 => array(
            'var' => 'intent_name',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        2 => array(
            'var' => 'chatbotID',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        3 => array(
            'var' => 'uid',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        4 => array(
            'var' => 'channel',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        5 => array(
            'var' => 'resolved',
            'isRequired' => false,
            'type' => TType::BOOL,
        ),
        6 => array(
            'var' => 'id',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        7 => array(
            'var' => 'entities',
            'isRequired' => false,
            'type' => TType::LST,
            'etype' => TType::STRUCT,
            'elem' => array(
                'type' => TType::STRUCT,
                'class' => '\Entity',
                ),
        ),
        8 => array(
            'var' => 'branch',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        9 => array(
            'var' => 'createdate',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        10 => array(
            'var' => 'updatedate',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
    );

    /**
     * @var string
     */
    public $intent_name = null;
    /**
     * @var string
     */
    public $chatbotID = null;
    /**
     * @var string
     */
    public $uid = null;
    /**
     * @var string
     */
    public $channel = null;
    /**
     * @var bool
     */
    public $resolved = null;
    /**
     * @var string
     */
    public $id = null;
    /**
     * @var \Entity[]
     */
    public $entities = null;
    /**
     * @var string
     */
    public $branch = null;
    /**
     * @var string
     */
    public $createdate = null;
    /**
     * @var string
     */
    public $updatedate = null;

    public function __construct($vals = null)
    {
        if (is_array($vals)) {
            if (isset($vals['intent_name'])) {
                $this->intent_name = $vals['intent_name'];
            }
            if (isset($vals['chatbotID'])) {
                $this->chatbotID = $vals['chatbotID'];
            }
            if (isset($vals['uid'])) {
                $this->uid = $vals['uid'];
            }
            if (isset($vals['channel'])) {
                $this->channel = $vals['channel'];
            }
            if (isset($vals['resolved'])) {
                $this->resolved = $vals['resolved'];
            }
            if (isset($vals['id'])) {
                $this->id = $vals['id'];
            }
            if (isset($vals['entities'])) {
                $this->entities = $vals['entities'];
            }
            if (isset($vals['branch'])) {
                $this->branch = $vals['branch'];
            }
            if (isset($vals['createdate'])) {
                $this->createdate = $vals['createdate'];
            }
            if (isset($vals['updatedate'])) {
                $this->updatedate = $vals['updatedate'];
            }
        }
    }

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


    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->intent_name);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 2:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->chatbotID);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 3:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->uid);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 4:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->channel);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 5:
                    if ($ftype == TType::BOOL) {
                        $xfer += $input->readBool($this->resolved);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 6:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->id);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 7:
                    if ($ftype == TType::LST) {
                        $this->entities = array();
                        $_size14 = 0;
                        $_etype17 = 0;
                        $xfer += $input->readListBegin($_etype17, $_size14);
                        for ($_i18 = 0; $_i18 < $_size14; ++$_i18) {
                            $elem19 = null;
                            $elem19 = new \Entity();
                            $xfer += $elem19->read($input);
                            $this->entities []= $elem19;
                        }
                        $xfer += $input->readListEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 8:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->branch);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 9:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->createdate);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 10:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->updatedate);
                    } 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('ChatSession');
        if ($this->intent_name !== null) {
            $xfer += $output->writeFieldBegin('intent_name', TType::STRING, 1);
            $xfer += $output->writeString($this->intent_name);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->chatbotID !== null) {
            $xfer += $output->writeFieldBegin('chatbotID', TType::STRING, 2);
            $xfer += $output->writeString($this->chatbotID);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->uid !== null) {
            $xfer += $output->writeFieldBegin('uid', TType::STRING, 3);
            $xfer += $output->writeString($this->uid);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->channel !== null) {
            $xfer += $output->writeFieldBegin('channel', TType::STRING, 4);
            $xfer += $output->writeString($this->channel);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->resolved !== null) {
            $xfer += $output->writeFieldBegin('resolved', TType::BOOL, 5);
            $xfer += $output->writeBool($this->resolved);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->id !== null) {
            $xfer += $output->writeFieldBegin('id', TType::STRING, 6);
            $xfer += $output->writeString($this->id);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->entities !== null) {
            if (!is_array($this->entities)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('entities', TType::LST, 7);
            $output->writeListBegin(TType::STRUCT, count($this->entities));
            foreach ($this->entities as $iter20) {
                $xfer += $iter20->write($output);
            }
            $output->writeListEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->branch !== null) {
            $xfer += $output->writeFieldBegin('branch', TType::STRING, 8);
            $xfer += $output->writeString($this->branch);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->createdate !== null) {
            $xfer += $output->writeFieldBegin('createdate', TType::STRING, 9);
            $xfer += $output->writeString($this->createdate);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->updatedate !== null) {
            $xfer += $output->writeFieldBegin('updatedate', TType::STRING, 10);
            $xfer += $output->writeString($this->updatedate);
            $xfer += $output->writeFieldEnd();
        }
        $xfer += $output->writeFieldStop();
        $xfer += $output->writeStructEnd();
        return $xfer;
    }
}
