<?php

namespace App\Master\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Mtc\MercuryDataModels\User;
use Stancl\Tenancy\Database\Concerns\CentralConnection;

class ModelRequest extends Model
{
    use CentralConnection;

    protected $table = 'model_requests';

    protected $fillable = [
        'make_id',
        'model_name',
        'vehicle_type',
        'reason',
        'requested_by_email',
        'requested_by_name',
        'tenant_id',
        'status',
        'approved_by',
        'actioned_at',
        'admin_notes',
    ];

    protected $casts = [
        'actioned_at' => 'datetime',
    ];

    public function make(): BelongsTo
    {
        return $this->belongsTo(VehicleMake::class, 'make_id');
    }

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

    public function scopePending($query)
    {
        return $query->where('status', 'pending');
    }

    public function scopeApproved($query)
    {
        return $query->where('status', 'approved');
    }

    public function scopeRejected($query)
    {
        return $query->where('status', 'rejected');
    }

    public function isPending(): bool
    {
        return $this->status === 'pending';
    }

    public function isApproved(): bool
    {
        return $this->status === 'approved';
    }

    public function isRejected(): bool
    {
        return $this->status === 'rejected';
    }
}
