<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Attributes\Scope;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Veelasky\LaravelHashId\Eloquent\HashableId;

class RestockItem extends Model
{
    use HashableId, SoftDeletes;

    protected $guarded = ['id'];

    protected function casts(): array
    {
        return [
            'quantity' => 'int',
        ];
    }

    #[Scope]
    public function currentUser(Builder $query): void
    {
        $query->where('user_id', auth()->id());
    }

    public function restock(): BelongsTo
    {
        return $this->belongsTo(Restock::class);
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    public function restockable(): MorphTo
    {
        return $this->morphTo();
    }
}
