<?php

namespace App\Models;

use App\Enums\QrRenderFormat;
use Database\Factories\QrCodeRenderFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;

/**
 * A single QR code image generation/download event, distinct from a scan.
 *
 * @property int $id
 * @property int $qr_code_id
 * @property QrRenderFormat $format
 * @property string|null $ip_address
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 * @property-read QrCode $qrCode
 */
#[Fillable(['qr_code_id', 'format', 'ip_address'])]
class QrCodeRender extends Model
{
    /** @use HasFactory<QrCodeRenderFactory> */
    use HasFactory;

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'qr_code_renders';

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'format' => QrRenderFormat::class,
        ];
    }

    /**
     * Get the QR code this render belongs to.
     *
     * @return BelongsTo<QrCode, $this>
     */
    public function qrCode(): BelongsTo
    {
        return $this->belongsTo(QrCode::class);
    }
}
