<?php

namespace App\Models;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\HasOne;

class Product extends Model
{
    //use soft delete
    use SoftDeletes;

    protected $fillable = [
        'foodics_id', 'sku', 'barcode', 'image', 'is_active', 'is_stock_product', 'is_ready', 'pricing_method',	'selling_method',	'costing_method', 'preparation_time', 'price', 'cost', 'calories', 'category_id', 'body'
    ];


    public function getNameAttribute()
    {
        return $this->currentDescription->name;
    }
    /**
     * Get current description of the the Room
     * @return HasOne
     */
    public function currentDescription() :HasOne
    {
        return $this->hasOne(ProductDescription::class)->where('language_id', currentLanguage()->id);
    }

    public function orders()
    {
        return $this->hasMany(OrderProduct::class,'product_id','foodics_id');
    }

    public function group()
    {
        return $this->hasOne(GroupProduct::class,'product_id','foodics_id');
    }

    public function groups()
    {
        return $this->hasMany(GroupProduct::class,'product_id','foodics_id');
    }

}
