<?php

namespace App\Models\GIS;

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

class GisFeatureGeometry extends Model
{
    protected $table = 'gis_feature_geometries';

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

    protected $primaryKey = 'uuid';

    protected $fillable = ['feature_id','coordinates','raw_shape'];

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

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

    public function feature()
    {
        return $this->belongsTo(GisFeature::class, 'feature_id', 'uuid');
    }
}
