<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class InspectionTemplate extends Model
{
    protected $fillable = ['name', 'description', 'project_id', 'fields'];

    protected $casts = ['fields' => 'array'];

    /** Proyecto que la creó (informativo; ya no determina visibilidad). */
    public function project()
    {
        return $this->belongsTo(Project::class);
    }

    /** Proyectos a los que está asignada esta plantilla (pivot). */
    public function projects()
    {
        return $this->belongsToMany(Project::class, 'inspection_template_project')->withTimestamps();
    }

    public function inspections()
    {
        return $this->hasMany(Inspection::class);
    }
}
