<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Area extends Model
{
    protected $fillable = ['code', 'name', 'region', 'metadata', 'geom_polygon'];

    /** Exclude binary geometry from array/JSON/serialization (e.g. cache). */
    protected $hidden = ['geom_polygon'];

    protected $casts = [
        'metadata' => 'array',
    ];

    public function doctors(): HasMany
    {
        return $this->hasMany(Doctor::class, 'area_id');
    }

    public function mrAssignments(): HasMany
    {
        return $this->hasMany(MrAreaAssignment::class, 'area_id');
    }

    public function visits(): HasMany
    {
        return $this->hasMany(Visit::class, 'area_id_resolved');
    }
}
