<?php

namespace App\Models;

use App\Enums\VerificationStatus;
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\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Swindon\FilamentHashids\Traits\HasHashid;

class VerificationRequest extends Model
{
    use HasHashid, SoftDeletes;

    protected $guarded = ['id'];

    protected function casts(): array
    {
        return [
            'status' => VerificationStatus::class,
            'company_id' => 'integer',
            'submitted_by' => 'integer',
        ];
    }

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

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

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

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

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

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

    public function reviews(): HasMany
    {
        return $this->hasMany(VerificationReview::class);
    }
}
