<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Layer extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'project_id', 'phase_id', 'name', 'color', 'geojson_data', 'original_file', 'uploaded_by',
    ];

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

    public function project()
    {
        return $this->belongsTo(Project::class);
    }

    public function phase()
    {
        return $this->belongsTo(Phase::class);
    }

    public function uploader()
    {
        return $this->belongsTo(User::class, 'uploaded_by');
    }

    public function features()
    {
        return $this->hasMany(Feature::class);
    }

    public function issues()
    {
        return $this->hasMany(Issue::class);
    }

    public function media()
    {
        return $this->morphMany(Media::class, 'mediable');
    }
}
