<?php

namespace App\Models\GIS;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class GisFeatureCollection extends Model
{
    protected $table = 'gis_feature_collections';

    protected $primaryKey = 'uuid';

    public $incrementing = false; // UUID, not auto-increment
    protected $keyType = 'string';

    protected $fillable = ['name', 'description'];

    protected static function boot(): void
    {
        parent::boot();
        static::creating(function ($model) {
            if (!$model->uuid) {
                $model->uuid = (string) Str::uuid();
            }
        });
    }

    public function features()
    {
        return $this->hasMany(GisFeature::class, 'collection_id', 'uuid');
    }
}