<?php

namespace app\modules\hub\models\db;

use Yii;

/**
 * This is the model class for table "ist_peers".
 *
 * @property int $id
 * @property int $hub_id
 * @property string $pid
 * @property string $addr
 * @property string $status
 * @property string $timestamp
 * @property string $created_on
 *
 * @property IstHub $hub
 * @property IstSessionPeers[] $istSessionPeers
 */
class IstPeers extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'ist_peers';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['hub_id', 'pid', 'addr', 'created_on'], 'required'],
            [['hub_id'], 'integer'],
            [['status'], 'string'],
            [['timestamp', 'created_on'], 'safe'],
            [['pid'], 'string', 'max' => 28],
            [['addr'], 'string', 'max' => 64],
            [['hub_id'], 'exist', 'skipOnError' => true, 'targetClass' => IstHub::className(), 'targetAttribute' => ['hub_id' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'hub_id' => 'Hub ID',
            'pid' => 'Pid',
            'addr' => 'Addr',
            'status' => 'Status',
            'timestamp' => 'Timestamp',
            'created_on' => 'Created On',
        ];
    }

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

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