<?php
    
    namespace common\models;
    
    use common\modules\language\behaviors\LanguageBehavior;
    use Yii;
    use yii\db\ActiveQuery;
    use yii\db\ActiveRecord;
    use yii\web\Request;
    
    /**
     * Class Delivery
     * * From language behavior *
     * @property OrdersDeliveryLang   $lang
     * @property OrdersDeliveryLang[] $langs
     * @property OrdersDeliveryLang   $object_lang
     * @property string               $ownerKey
     * @property string               $langKey
     * @property OrdersDeliveryLang[] $model_langs
     * @property integer              $id
     * @property integer              $parent_id
     * @property integer              $sort
     * @property integer              $value
     * @property bool                 $transactionStatus
     * @property Delivery             $parent
     * @method string           getOwnerKey()
     * @method void             setOwnerKey( string $value )
     * @method string           getLangKey()
     * @method void             setLangKey( string $value )
     * @method ActiveQuery      getLangs()
     * @method ActiveQuery      getLang( integer $language_id )
     * @method OrdersDeliveryLang[]    generateLangs()
     * @method void             loadLangs( Request $request )
     * @method bool             linkLangs()
     * @method bool             saveLangs()
     * @method bool             getTransactionStatus()
     * * End language behavior *
     */
    class Delivery extends ActiveRecord
    {
        
        public function behaviors()
        {
            return [
                'language' => [
                    'class'       => LanguageBehavior::className(),
                    'object_lang' => OrdersDeliveryLang::className(),
                    // optional, default to {TableLang}::className()
                    'ownerKey'    => 'id',
                    //optional, default to {Table}->primaryKey()[0]
                    'langKey'     => 'orders_delivery_id',
                ],
            ];
        }
        
        public static function tableName()
        {
            return 'orders_delivery';
        }
        
        public function rules()
        {
            return [
                [
                    [
                        'value' => Yii::t('app', 'value'),
                        'parent_id' => Yii::t('app', 'parent_id'),
                        'sort' => Yii::t('app', 'sort'),
                    ],
                    'integer',
                ],
            ];
        }
        
        public function getParent()
        {
            return $this->hasOne(self::className(), [ 'id' => 'parent_id' ]);
        }
    }