<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class Attachment extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = [
        'attachmentable_id',
        'attachmentable_type',
        'name',
        'extension',
        'size',
        'type',
    ];

    public function getFormattedAttachmentAttribute(): string
    {
        return $this->created_at->format('Y-m-d').'/'.$this->name.'.'.$this->extension;
    }

    public function attachmentable(): MorphTo
    {
        return $this->morphTo();
    }
}
