<?php
    
    namespace backend\components\imagemanager\models;
    
    use artbox\core\models\Language;
    use Yii;
    use yii\db\ActiveRecord;
    
    /**
     * This is the model class for table "ImageManagerLang".
     *
     * @property integer      $image_id
     * @property integer      $language_id
     * @property string       $title
     * @property string       $alt
     * @property string       $description
     * @property ImageManager $image
     * @property Language     $language
     */
    class ImageManagerLang extends ActiveRecord
    {
        /**
         * @inheritdoc
         */
        public static function tableName()
        {
            return 'ImageManagerLang';
        }
    
        /**
         * @inheritdoc
         */
        public static function primaryKey()
        {
            return [
                'image_id',
                'language_id',
            ];
        }
    
        /**
         * @inheritdoc
         */
        public function rules()
        {
            return [
                [
                    [
                        'image_id',
                        'language_id',
                    ],
                    'integer',
                ],
                [
                    [
                        'title',
                        'alt',
                        'description',
                    ],
                    'string',
                    'max' => 255,
                ],
                [
                    [
                        'language_id',
                        'image_id',
                    ],
                    'unique',
                    'targetAttribute' => [
                        'language_id',
                        'image_id',
                    ],
                    'message'         => 'The combination of Image ID and Language ID has already been taken.',
                ],
                [
                    [ 'image_id' ],
                    'exist',
                    'skipOnError'     => true,
                    'targetClass'     => ImageManager::className(),
                    'targetAttribute' => [ 'image_id' => 'id' ],
                ],
                [
                    [ 'language_id' ],
                    'exist',
                    'skipOnError'     => true,
                    'targetClass'     => Language::className(),
                    'targetAttribute' => [ 'language_id' => 'id' ],
                ],
            ];
        }
        
        /**
         * @inheritdoc
         */
        public function attributeLabels()
        {
            return [
                'image_id'    => Yii::t('app', 'Image ID'),
                'language_id' => Yii::t('app', 'Language ID'),
                'title'       => Yii::t('app', 'Title'),
                'alt'         => Yii::t('app', 'Alt'),
                'description' => Yii::t('app', 'Description'),
            ];
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getImage()
        {
            return $this->hasOne(ImageManager::className(), [ 'id' => 'image_id' ]);
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getLanguage()
        {
            return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]);
        }
    }
