<?php

namespace App\Models;

use App\Enums\PriceRequestStatus;
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\SoftDeletes;
use Veelasky\LaravelHashId\Eloquent\HashableId;

class PriceRequest extends Model
{
    use HashableId, SoftDeletes;

    protected $guarded = ['id'];

    protected function casts(): array
    {
        return [
            'status' => PriceRequestStatus::class,
            'finalized_at' => 'datetime',
        ];
    }

    #[Scope]
    protected function pending(Builder $query): void
    {
        $query->where('status', PriceRequestStatus::PENDING->value);
    }

    #[Scope]
    protected function approved(Builder $query): void
    {
        $query->where('status', PriceRequestStatus::APPROVED->value);
    }

    #[Scope]
    protected function rejected(Builder $query): void
    {
        $query->where('status', PriceRequestStatus::REJECTED->value);
    }

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