<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;

/**
 * Per-file storage registry row. Written by App\Services\MediaStorage on
 * every upload; dropped on delete. The (disk, path) pair is unique — moving
 * a file across disks updates the row in place rather than creating a new
 * one.
 *
 * `owner()` is a polymorphic pointer at the domain row that owns the file
 * (Project / ThemeVersion / branding singleton / etc.) so delete-by-owner
 * sweeps can find every file we wrote without the domain row tracking a
 * list. `owner_type` is a short string (`'project'` / `'theme'` / `'kit'` /
 * `'branding'` / `'export'` / `'user'`) — not the FQCN — so cross-namespace
 * refactors don't break stored references.
 */
class MediaFile extends Model
{
    protected $fillable = [
        'disk',
        'path',
        'original_name',
        'mime_type',
        'size_bytes',
        'owner_type',
        'owner_id',
        'purpose',
    ];

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