<?php
    
    namespace common\modules\rubrication\models;
    
    use common\modules\language\models\Language;
    use Yii;
    
    /**
     * This is the model class for table "tax_option_lang".
     * @property integer   $tax_option_id
     * @property integer   $language_id
     * @property string    $value
     * @property string    $alias
     * @property Language  $language
     * @property TaxOption $taxOption
     */
    class TaxOptionLang extends \yii\db\ActiveRecord
    {
        
        public static function primaryKey()
        {
            return [
                'tax_option_id',
                'language_id',
            ];
        }
        
        /**
         * @inheritdoc
         */
        public static function tableName()
        {
            return 'tax_option_lang';
        }
        
        public function behaviors()
        {
            return [
                'slug' => [
                    'class'         => 'common\behaviors\Slug',
                    'in_attribute'  => 'value',
                    'out_attribute' => 'alias',
                    'translit'      => true,
                ],
            ];
        }
        
        /**
         * @inheritdoc
         */
        public function rules()
        {
            return [
                [
                    [ 'value' ],
                    'required',
                ],
                [
                    [
                        'value',
                        'alias',
                    ],
                    'string',
                    'max' => 255,
                ],
                [
                    [
                        'tax_option_id',
                        'language_id',
                    ],
                    'unique',
                    'targetAttribute' => [
                        'tax_option_id',
                        'language_id',
                    ],
                    'message'         => 'The combination of Tax Option ID and Language ID has already been taken.',
                ],
                [
                    [ 'language_id' ],
                    'exist',
                    'skipOnError'     => true,
                    'targetClass'     => Language::className(),
                    'targetAttribute' => [ 'language_id' => 'language_id' ],
                ],
                [
                    [ 'tax_option_id' ],
                    'exist',
                    'skipOnError'     => true,
                    'targetClass'     => TaxOption::className(),
                    'targetAttribute' => [ 'tax_option_id' => 'tax_option_id' ],
                ],
            ];
        }
        
        /**
         * @inheritdoc
         */
        public function attributeLabels()
        {
            return [
                'tax_option_id' => Yii::t('app', 'Tax Option ID'),
                'language_id'   => Yii::t('app', 'Language ID'),
                'value'         => Yii::t('app', 'Value'),
                'alias'         => Yii::t('app', 'Alias'),
            ];
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getLanguage()
        {
            return $this->hasOne(Language::className(), [ 'language_id' => 'language_id' ]);
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getTaxOption()
        {
            return $this->hasOne(TaxOption::className(), [ 'tax_option_id' => 'tax_option_id' ]);
        }
    }
