<?php
namespace App\Traits;

trait GeneratesReference
{
    /**
     * Génère une référence unique du type : PREFIX-YYYY-NNNN
     * Ex: CND-2026-0001, BSN-2026-0042, MSN-2026-0001
     */
    public static function generateReference(string $prefix): string
    {
        $year = date('Y');
        $count = static::whereYear('created_at', $year)->count() + 1;
        return sprintf('%s-%s-%04d', $prefix, $year, $count);
    }
}
