<?php

namespace App\Models\GIS;

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

class GisFeature extends Model
{
    protected $table = 'gis_features';

    public $incrementing = false;
    protected $keyType = 'string';

    protected $primaryKey = 'uuid';

    protected $fillable = ['type','geometry_type','active','hide','zoom','collection_id'];


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

    public function collection()
    {
        return $this->belongsTo(GisFeatureCollection::class, 'collection_id', 'uuid');
    }

    public function properties()
    {
        return $this->hasMany(GisFeatureProperty::class, 'feature_id', 'uuid');
    }

    public function geometries()
    {
        return $this->hasMany(GisFeatureGeometry::class, 'feature_id', 'uuid');
    }
}