<?php

namespace app\modules\hub\models\db;

use Yii;

/**
 * This is the model class for table "ist_session_peers".
 *
 * @property int $id
 * @property int $session_id
 * @property int $peer_id
 * @property string $peer_type
 * @property string $peer_state
 * @property string $timestamp
 * @property string $created_on
 *
 * @property IstPeers $peer
 * @property IstSession $session
 */
class IstSessionPeers extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'ist_session_peers';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['session_id', 'peer_id', 'peer_type', 'created_on'], 'required'],
            [['session_id', 'peer_id'], 'integer'],
            [['peer_type', 'peer_state'], 'string'],
            [['timestamp', 'created_on'], 'safe'],
            [['peer_id'], 'exist', 'skipOnError' => true, 'targetClass' => IstPeers::className(), 'targetAttribute' => ['peer_id' => 'id']],
            [['session_id'], 'exist', 'skipOnError' => true, 'targetClass' => IstSession::className(), 'targetAttribute' => ['session_id' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'session_id' => 'Session ID',
            'peer_id' => 'Peer ID',
            'peer_type' => 'Peer Type',
            'peer_state' => 'Peer State',
            'timestamp' => 'Timestamp',
            'created_on' => 'Created On',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPeer()
    {
        return $this->hasOne(IstPeers::className(), ['id' => 'peer_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getSession()
    {
        return $this->hasOne(IstSession::className(), ['id' => 'session_id']);
    }
}
