<?php

namespace App\Models;

use App\Models\Scopes\ActiveProductScope;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Product extends BaseModel
{
    use HasFactory;

    public const STATUS_ACTIVE = 'active';

    public const STATUS_INACTIVE = 'inactive';

    protected $guarded = [];

    protected static function booted(): void
    {
        static::addGlobalScope(new ActiveProductScope);
    }

    public function category()
    {
        return $this->hasOne(Category::class, 'id', 'category_id')->with('Parent');
    }

    public function attribute()
    {
        return $this->hasMany(productAttribute::class)->with('color', 'unit', 'brand', 'model', 'size', 'warehouse', 'origin', 'shopOpening', 'shelf', 'diamondUnit', 'goldUnit', 'productType');
    }

    public function isActive(): bool
    {
        return ($this->status ?? self::STATUS_ACTIVE) === self::STATUS_ACTIVE;
    }
}
