<?php

namespace App\Models;

use App\Enums\DecisionAdmin;
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 Swindon\FilamentHashids\Traits\HasHashid;

class VerificationReview extends Model
{
    use HasHashid, SoftDeletes;

    protected $guarded = ['id'];

    protected function casts(): array
    {
        return [
            'decision' => DecisionAdmin::class,
            'verification_request_id' => 'integer',
            'reviewer_id' => 'integer',
        ];
    }

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

    #[Scope]
    protected function needRevision(Builder $query): void
    {
        $query->where('decision', DecisionAdmin::NEED_REVISION);
    }

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

    public function reviewer(): BelongsTo
    {
        return $this->belongsTo(User::class, 'reviewer_id');
    }

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