<?php

namespace common\modules\triggers\models;

use Yii;

/**
 * This is the model class for table "trigger_condition".
 *
 * @property integer $id
 * @property integer $group_number
 * @property integer $trigger_id
 * @property integer $condition_id
 *
 * @property TriggerTrigger $trigger
 * @property TriggerParam[] $triggerParams
 */
class TriggerCondition extends \common\components\ActiveRecordModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'trigger_condition';
    }

    public function name()
    {
        return 'Условия триггера';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['group_number', 'trigger_id', 'condition_id'], 'required'],
            [['group_number', 'trigger_id', 'condition_id'], 'integer'],
            [['trigger_id'], 'exist', 'skipOnError' => true, 'targetClass' => TriggerTrigger::className(), 'targetAttribute' => ['trigger_id' => 'id']],
        ];
    }

    public function behaviors(){
        return [];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'group_number' => 'Group Number',
            'trigger_id' => 'Trigger ID',
            'condition_id' => 'Идентификатор условия'
        ];
    }

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

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