<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "main_categories".
 *
 * @property int $id
 * @property string|null $image_path
 * @property string $arabic_name
 * @property string $english_name
 *
 * @property Items[] $items
 * @property SubCategories[] $subCategories
 */
class MainCategories extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'main_categories';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['arabic_name', 'english_name'], 'required'],
            [['image_path'], 'string', 'max' => 500],
            [['arabic_name', 'english_name'], 'string', 'max' => 200],
            [['image_path'], 'safe'],
            [['image_path'], 'file', 'extensions'=>'jpg, png, jpeg'],
            [['status'], 'string'],
            [['status'], 'default','value'=> 'Active'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'image_path' => Yii::t('app', 'Image'),
            'arabic_name' => Yii::t('app', 'Arabic Name'),
            'english_name' => Yii::t('app', 'English Name'),
            'status' => Yii::t('app', 'Status'),
        ];
    }

    /**
     * Gets query for [[Items]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getItems()
    {
        return $this->hasMany(Items::className(), ['main_category_id' => 'id'])
        ->andOnCondition(['status' => 'Active']);
    }

    /**
     * Gets query for [[SubCategories]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getSubCategories()
    {
        return $this->hasMany(SubCategories::className(), ['main_category_id' => 'id']);
    }
}
