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

    static public $_TSPEC = array(
        1 => array(
            'var' => 'session_id',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        2 => array(
            'var' => 'chatbotID',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        3 => array(
            'var' => 'type',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        4 => array(
            'var' => 'direction',
            'isRequired' => false,
            'type' => TType::I32,
        ),
        5 => array(
            'var' => 'branch',
            'isRequired' => false,
            'type' => TType::I32,
        ),
        6 => array(
            'var' => 'sender',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        7 => array(
            'var' => 'receiver',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        8 => array(
            'var' => 'createdate',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        9 => array(
            'var' => 'id',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        10 => array(
            'var' => 'textMessage',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        11 => array(
            'var' => 'audioMessage',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        12 => array(
            'var' => 'videoMessage',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        13 => array(
            'var' => 'imageMessage',
            'isRequired' => false,
            'type' => TType::STRING,
        ),
        14 => array(
            'var' => 'terms',
            'isRequired' => false,
            'type' => TType::LST,
            'etype' => TType::STRING,
            'elem' => array(
                'type' => TType::STRING,
                ),
        ),
        15 => array(
            'var' => 'tags',
            'isRequired' => false,
            'type' => TType::LST,
            'etype' => TType::STRING,
            'elem' => array(
                'type' => TType::STRING,
                ),
        ),
        16 => array(
            'var' => 'is_fallback',
            'isRequired' => false,
            'type' => TType::BOOL,
        ),
        17 => array(
            'var' => 'is_proactive',
            'isRequired' => false,
            'type' => TType::BOOL,
        ),
    );

    /**
     * @var string
     */
    public $session_id = null;
    /**
     * @var string
     */
    public $chatbotID = null;
    /**
     * @var string
     */
    public $type = null;
    /**
     * @var int
     */
    public $direction = null;
    /**
     * @var int
     */
    public $branch = null;
    /**
     * @var string
     */
    public $sender = null;
    /**
     * @var string
     */
    public $receiver = null;
    /**
     * @var string
     */
    public $createdate = null;
    /**
     * @var string
     */
    public $id = null;
    /**
     * @var string
     */
    public $textMessage = null;
    /**
     * @var string
     */
    public $audioMessage = null;
    /**
     * @var string
     */
    public $videoMessage = null;
    /**
     * @var string
     */
    public $imageMessage = null;
    /**
     * @var string[]
     */
    public $terms = null;
    /**
     * @var string[]
     */
    public $tags = null;
    /**
     * @var bool
     */
    public $is_fallback = null;
    /**
     * @var bool
     */
    public $is_proactive = null;

    public function __construct($vals = null)
    {
        if (is_array($vals)) {
            if (isset($vals['session_id'])) {
                $this->session_id = $vals['session_id'];
            }
            if (isset($vals['chatbotID'])) {
                $this->chatbotID = $vals['chatbotID'];
            }
            if (isset($vals['type'])) {
                $this->type = $vals['type'];
            }
            if (isset($vals['direction'])) {
                $this->direction = $vals['direction'];
            }
            if (isset($vals['branch'])) {
                $this->branch = $vals['branch'];
            }
            if (isset($vals['sender'])) {
                $this->sender = $vals['sender'];
            }
            if (isset($vals['receiver'])) {
                $this->receiver = $vals['receiver'];
            }
            if (isset($vals['createdate'])) {
                $this->createdate = $vals['createdate'];
            }
            if (isset($vals['id'])) {
                $this->id = $vals['id'];
            }
            if (isset($vals['textMessage'])) {
                $this->textMessage = $vals['textMessage'];
            }
            if (isset($vals['audioMessage'])) {
                $this->audioMessage = $vals['audioMessage'];
            }
            if (isset($vals['videoMessage'])) {
                $this->videoMessage = $vals['videoMessage'];
            }
            if (isset($vals['imageMessage'])) {
                $this->imageMessage = $vals['imageMessage'];
            }
            if (isset($vals['terms'])) {
                $this->terms = $vals['terms'];
            }
            if (isset($vals['tags'])) {
                $this->tags = $vals['tags'];
            }
            if (isset($vals['is_fallback'])) {
                $this->is_fallback = $vals['is_fallback'];
            }
            if (isset($vals['is_proactive'])) {
                $this->is_proactive = $vals['is_proactive'];
            }
        }
    }

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


    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->session_id);
                    } 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->type);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 4:
                    if ($ftype == TType::I32) {
                        $xfer += $input->readI32($this->direction);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 5:
                    if ($ftype == TType::I32) {
                        $xfer += $input->readI32($this->branch);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 6:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->sender);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 7:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->receiver);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 8:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->createdate);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 9:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->id);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 10:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->textMessage);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 11:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->audioMessage);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 12:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->videoMessage);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 13:
                    if ($ftype == TType::STRING) {
                        $xfer += $input->readString($this->imageMessage);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 14:
                    if ($ftype == TType::LST) {
                        $this->terms = array();
                        $_size0 = 0;
                        $_etype3 = 0;
                        $xfer += $input->readListBegin($_etype3, $_size0);
                        for ($_i4 = 0; $_i4 < $_size0; ++$_i4) {
                            $elem5 = null;
                            $xfer += $input->readString($elem5);
                            $this->terms []= $elem5;
                        }
                        $xfer += $input->readListEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 15:
                    if ($ftype == TType::LST) {
                        $this->tags = array();
                        $_size6 = 0;
                        $_etype9 = 0;
                        $xfer += $input->readListBegin($_etype9, $_size6);
                        for ($_i10 = 0; $_i10 < $_size6; ++$_i10) {
                            $elem11 = null;
                            $xfer += $input->readString($elem11);
                            $this->tags []= $elem11;
                        }
                        $xfer += $input->readListEnd();
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 16:
                    if ($ftype == TType::BOOL) {
                        $xfer += $input->readBool($this->is_fallback);
                    } else {
                        $xfer += $input->skip($ftype);
                    }
                    break;
                case 17:
                    if ($ftype == TType::BOOL) {
                        $xfer += $input->readBool($this->is_proactive);
                    } 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('ChatMessage');
        if ($this->session_id !== null) {
            $xfer += $output->writeFieldBegin('session_id', TType::STRING, 1);
            $xfer += $output->writeString($this->session_id);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->chatbotID !== null) {
            $xfer += $output->writeFieldBegin('chatbotID', TType::STRING, 2);
            $xfer += $output->writeString($this->chatbotID);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->type !== null) {
            $xfer += $output->writeFieldBegin('type', TType::STRING, 3);
            $xfer += $output->writeString($this->type);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->direction !== null) {
            $xfer += $output->writeFieldBegin('direction', TType::I32, 4);
            $xfer += $output->writeI32($this->direction);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->branch !== null) {
            $xfer += $output->writeFieldBegin('branch', TType::I32, 5);
            $xfer += $output->writeI32($this->branch);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->sender !== null) {
            $xfer += $output->writeFieldBegin('sender', TType::STRING, 6);
            $xfer += $output->writeString($this->sender);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->receiver !== null) {
            $xfer += $output->writeFieldBegin('receiver', TType::STRING, 7);
            $xfer += $output->writeString($this->receiver);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->createdate !== null) {
            $xfer += $output->writeFieldBegin('createdate', TType::STRING, 8);
            $xfer += $output->writeString($this->createdate);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->id !== null) {
            $xfer += $output->writeFieldBegin('id', TType::STRING, 9);
            $xfer += $output->writeString($this->id);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->textMessage !== null) {
            $xfer += $output->writeFieldBegin('textMessage', TType::STRING, 10);
            $xfer += $output->writeString($this->textMessage);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->audioMessage !== null) {
            $xfer += $output->writeFieldBegin('audioMessage', TType::STRING, 11);
            $xfer += $output->writeString($this->audioMessage);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->videoMessage !== null) {
            $xfer += $output->writeFieldBegin('videoMessage', TType::STRING, 12);
            $xfer += $output->writeString($this->videoMessage);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->imageMessage !== null) {
            $xfer += $output->writeFieldBegin('imageMessage', TType::STRING, 13);
            $xfer += $output->writeString($this->imageMessage);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->terms !== null) {
            if (!is_array($this->terms)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('terms', TType::LST, 14);
            $output->writeListBegin(TType::STRING, count($this->terms));
            foreach ($this->terms as $iter12) {
                $xfer += $output->writeString($iter12);
            }
            $output->writeListEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->tags !== null) {
            if (!is_array($this->tags)) {
                throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
            }
            $xfer += $output->writeFieldBegin('tags', TType::LST, 15);
            $output->writeListBegin(TType::STRING, count($this->tags));
            foreach ($this->tags as $iter13) {
                $xfer += $output->writeString($iter13);
            }
            $output->writeListEnd();
            $xfer += $output->writeFieldEnd();
        }
        if ($this->is_fallback !== null) {
            $xfer += $output->writeFieldBegin('is_fallback', TType::BOOL, 16);
            $xfer += $output->writeBool($this->is_fallback);
            $xfer += $output->writeFieldEnd();
        }
        if ($this->is_proactive !== null) {
            $xfer += $output->writeFieldBegin('is_proactive', TType::BOOL, 17);
            $xfer += $output->writeBool($this->is_proactive);
            $xfer += $output->writeFieldEnd();
        }
        $xfer += $output->writeFieldStop();
        $xfer += $output->writeStructEnd();
        return $xfer;
    }
}
