<?php

namespace common\modules\triggers\models;

use Yii;
use common\modules\users\models\User;

/**
 * This is the model class for table "trigger_scenario".
 *
 * @property integer $id
 * @property integer $active
 * @property integer $owner_id
 * @property string $name
 * @property string $description
 * @property string $date_create
 *
 * @property TriggerConnection[] $triggerConnections
 * @property User $owner
 */
class TriggerScenario extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'trigger_scenario';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['active', 'owner_id'], 'integer'],
            [['owner_id', 'name', 'date_create'], 'required'],
            [['description'], 'string'],
            [['date_create'], 'safe'],
            [['name'], 'string', 'max' => 255],
            [['owner_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['owner_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'active' => 'Active',
            'owner_id' => 'Owner ID',
            'name' => 'Name',
            'description' => 'Description',
            'date_create' => 'Date Create',
        ];
    }

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

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