<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;

class ComunicadoImagen extends Model
{
    protected $table = 'comunicado_imagenes';

    protected $fillable = [
        'comunicado_id',
        'imagen_path',
        'orden',
    ];

    protected $casts = [
        'orden' => 'integer',
    ];

    protected $appends = ['imagen_url'];

    public function getImagenUrlAttribute(): ?string
    {
        return $this->imagen_path
            ? Storage::disk('public')->url($this->imagen_path)
            : null;
    }

    public function comunicado(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(Comunicado::class);
    }
}
