<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\ServicePoint;
use App\Models\User;
use App\Models\TripRequest;
use App\Models\Trip;

class WorkingArea extends Model
{
    use HasFactory;

    protected $fillable = [
        'city_name',
        'city_name_ar',
        'center_lat',
        'center_lng',
        'zoom_level',
        'boundaries',
        'description',
        'is_active',
    ];

    protected $casts = [
        'center_lat' => 'decimal:8',
        'center_lng' => 'decimal:8',
        'zoom_level' => 'integer',
        'is_active' => 'boolean',
    ];

    /**
     * Get the service points for this working area.
     */
    public function servicePoints()
    {
        return $this->hasMany(ServicePoint::class);
    }

    /**
     * Get the active working area.
     */
    public static function getActiveArea()
    {
        return static::where('is_active', true)->first();
    }

    /**
     * Scope to get only active areas.
     */
    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }
}
