<?php

namespace common\modules\triggers\models;

use Yii;
use common\modules\content\models\CoContent;
use common\modules\users\models\User;
use common\modules\messageTemplate\models\MessageTemplate;

/**
 * This is the model class for table "cases_schedule".
 *
 * @property integer $id
 * @property integer $user_id
 * @property integer $case_id
 * @property integer $template_id
 * @property string $sended_date
 * @property integer $sended
 * @property integer $actual
 *
 * @property MessageTemplate $template
 * @property CoContent $case
 * @property User $user
 */
class CasesSchedule extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'cases_schedule';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'case_id'], 'required'],
            [['user_id', 'case_id', 'template_id', 'sended', 'actual'], 'integer'],
            [['sended_date'], 'safe'],
            [['template_id'], 'exist', 'skipOnError' => true, 'targetClass' => MessageTemplate::className(), 'targetAttribute' => ['template_id' => 'id']],
            [['case_id'], 'exist', 'skipOnError' => true, 'targetClass' => CoContent::className(), 'targetAttribute' => ['case_id' => 'id']],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => 'User ID',
            'case_id' => 'Case ID',
            'template_id' => 'Template ID',
            'sended_date' => 'Sended Date',
            'sended' => 'Sended',
            'actual' => 'Actual',
        ];
    }

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

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

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