<?php
    
    namespace common\models;
    
    use artbox\core\models\Alias;
    use artbox\core\models\Language;
    use Yii;
    use yii\helpers\Json;

    /**
     * This is the model class for table "service_lang".
     *
     * @property int      $service_id
     * @property int      $language_id
     * @property string   $title
     * @property string   $body
     * @property int      $alias_id
     * @property Alias    $alias
     * @property Language $language
     * @property Service  $service
     */
    class ServiceLang extends \yii\db\ActiveRecord
    {
        /**
         * {@inheritdoc}
         */
        public static function tableName()
        {
            return 'service_lang';
        }
        
        /**
         * {@inheritdoc}
         */
        public function rules()
        {
            return [
                [
                    [
                        'service_id',
                        'language_id',
                        'alias_id',
                    ],
                    'default',
                    'value' => null,
                ],
                [
                    [
                        'service_id',
                        'language_id',
                        'alias_id',
                    ],
                    'integer',
                ],
                [
                    [ 'body' ],
                    'string',
                ],
                [
                    [ 'title' ],
                    'string',
                    'max' => 255,
                ],
                [
                    [
                        'service_id',
                        'language_id',
                    ],
                    'unique',
                    'targetAttribute' => [
                        'service_id',
                        'language_id',
                    ],
                ],
                [
                    [ 'alias_id' ],
                    'exist',
                    'skipOnError'     => true,
                    'targetClass'     => Alias::className(),
                    'targetAttribute' => [ 'alias_id' => 'id' ],
                ],
                [
                    [ 'language_id' ],
                    'exist',
                    'skipOnError'     => true,
                    'targetClass'     => Language::className(),
                    'targetAttribute' => [ 'language_id' => 'id' ],
                ],
                [
                    [ 'service_id' ],
                    'exist',
                    'skipOnError'     => true,
                    'targetClass'     => Service::className(),
                    'targetAttribute' => [ 'service_id' => 'id' ],
                ],
            ];
        }
        
        /**
         * {@inheritdoc}
         */
        public function attributeLabels()
        {
            return [
                'service_id'  => Yii::t('app', 'Service ID'),
                'language_id' => Yii::t('app', 'Language ID'),
                'title'       => Yii::t('app', 'Title'),
                'body'        => Yii::t('app', 'Body'),
                'alias_id'    => Yii::t('app', 'Alias ID'),
            ];
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getAlias()
        {
            return $this->hasOne(Alias::className(), [ 'id' => 'alias_id' ]);
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getLanguage()
        {
            return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]);
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getService()
        {
            return $this->hasOne(Service::className(), [ 'id' => 'service_id' ]);
        }
    }
