<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "system_configurations".
 *
 * @property int $id
 * @property string $config_option
 * @property string $value
 */
class SystemConfigurations extends \yii\db\ActiveRecord
{
    public $max_var_num;
    public $max_item_images;
    public $logo;
    public $facebook_link;
    public $whatsapp_link;
    public $instagram_link;
    public $messenger_link;
    public $twitter_link;
    public $phone;
    public $restaurant_image;
    public $arabic_about;
    public $english_about;
    public $currency;
    public $currency_ar;

    public static function tableName()
    {
        return 'system_configurations';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['config_option'], 'required'],
            [['currency'], 'required', 'when' => function ($model) {
                if ($model->config_option != 'currency') {
                    return false;
                }
            }, 'whenClient' => 'function (attribute, value) { 
                    return true;
            }'],
            [['config_option'], 'string', 'max' => 50],
            [['arabic_about', 'english_about'], 'string', 'max' => 1000],
            [['facebook_link'], 'match', 'pattern' => '/^(https?:\/\/)?(www\.)?facebook.com\/[a-zA-Z0-9(\.\?)?]/'],
            [['instagram_link'], 'match', 'pattern' => '/^(https?:\/\/)?(www\.)?instagram.com\/[a-zA-Z0-9(\.\?)?]/'],
            [['currency','currency_ar'], 'match', 'pattern' => '/^([^0-9]*)$/'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'max_var_num' => Yii::t('app', 'Maximum Variations'),
            'max_item_images' => Yii::t('app', 'Maximum Item Images'),
            'logo' => Yii::t('app', 'Logo'),
            'facebook_link' => Yii::t('app', 'Facebook Link'),
            'whatsapp_link' => Yii::t('app', 'Whatsapp Link'),
            'instagram_link' => Yii::t('app', 'Instagram Link'),
            'messenger_link' => Yii::t('app', 'Messenger Link'),
            'twitter_link' => Yii::t('app', 'Twitter Link'),
            'restaurant_image' => Yii::t('app', 'Restaurant Image'),
            'arabic_about' => Yii::t('app', 'Arabic About'),
            'english_about' => Yii::t('app', 'English About'),
            'currency' => Yii::t('app', 'Currency English'),
            'currency_ar' => Yii::t('app', 'Currency Arabic'),
        ];
    }
}
