<?php

namespace common\modules\product\models;

use Yii;

/**
 * This is the model class for table "remote_products".
 *
 * @property string $Name
 * @property string $Price
 * @property string $Price_old
 * @property string $ID_chief
 * @property string $Article
 * @property string $Brand
 * @property string $ID
 * @property string $Date_create
 * @property integer $local_id
 * @property ProductVariant $product
 * @property RemoteCategories $remoteCategory
 */
class RemoteProducts extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'remote_products';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['Price', 'Price_old'], 'number'],
            [['Date_create'], 'safe'],
            [['Name'], 'string', 'max' => 100],
            [['ID_chief', 'Article', 'ID'], 'string', 'max' => 20],
            [['Brand'], 'string', 'max' => 25],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'Name' => Yii::t('product', 'Name'),
            'Price' => Yii::t('product', 'Price'),
            'Price_old' => Yii::t('product', 'Price Old'),
            'ID_chief' => Yii::t('product', 'Id Chief'),
            'Article' => Yii::t('product', 'Article'),
            'Brand' => Yii::t('product', 'Brand'),
            'ID' => Yii::t('product', 'ID'),
            'Date_create' => Yii::t('product', 'Date Create'),
            'local_id' => Yii::t('product', 'Local ID'),
        ];
    }

    public function getRemoteCategory() {
        if (empty($this->ID_chief)) {
            return null;
        }
        return RemoteCategories::findByID($this->ID_chief);
    }

    public function getProduct() {
        if (empty($this->ID)) {
            return null;
        }
        return ProductVariantSearch::findByRemoteID($this->ID);
    }
}
