<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class ProgramQrCode extends Model
{
    protected $fillable = ['program_id', 'token', 'qr_image_path', 'is_active'];

    protected function casts(): array
    {
        return ['is_active' => 'boolean'];
    }

    protected static function boot(): void
    {
        parent::boot();
        static::creating(fn($model) => $model->token ??= Str::random(48));
    }

    public function program()
    {
        return $this->belongsTo(Program::class);
    }
}
