<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

#[Fillable(['name', 'slug', 'city', 'pincode', 'lat', 'lng', 'is_active'])]
class Area extends Model
{
    use HasFactory;

    protected $casts = ['is_active' => 'boolean'];

    public function partners(): BelongsToMany
    {
        return $this->belongsToMany(PartnerProfile::class, 'partner_area', 'area_id', 'partner_id')
            ->withPivot('is_active');
    }

    public function scopeActive($q)
    {
        return $q->where('is_active', true);
    }

    public function scopeOrdered($q)
    {
        return $q->orderBy('name');
    }
}
