<?php
/*
    * Created by VahabDev in Aparat Live
    * Website: https://pourfi.ir
    * Aparat Live: https://www.aparat.com/vahabdev/live
    * Aparat Channel: https://www.aparat.com/vahabdev
    * Rubika Channel: https://rubika.ir/vahabdev
    * Donate: https://reymit.ir/vahabdev
    * Telegram: https://t.me/vahabdev
*/


namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Product extends Model
{
    protected $table = 'products';
    protected $fillable = [
        'name',
        'slug',
        'image',
        'description',
        'price',
        'discount',
        'seo_title',
        'seo_description',
        'seo_keywords',
        'status',
        'published_at',
        'category_id',
    ];


    public function orders() : HasMany{
        return $this->hasMany(Order::class, 'user_id', 'id');
    }

    public function files() : HasMany
    {
        return $this->hasMany(Files::class, 'product_id', 'id');
    }

    public function getStatusLabelAttribute(): string
    {
        return match($this->attributes['status']) {
            'active' => 'فعال',
            'inactive' => 'غیرفعال',
            default => 'فعال',
        };
    }


    public function category(): BelongsTo
    {
        return $this->belongsTo(productCategories::class, 'category_id', 'id');
    }

}
