<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Enquiry extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'email',
        'phone',
        'service',
        'message',
        'status',
    ];

    protected $casts = [
        'status' => 'string', // or you can use enum casting in Laravel 9+
    ];

    // Scopes (very useful for admin panel / backend)
    public function scopeNew($query)
    {
        return $query->where('status', 'new');
    }

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

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

    // Optional: default sorting - newest first
    protected static function booted()
    {
        static::addGlobalScope('latest', function ($query) {
            $query->latest();
        });
    }
}
