<?php

declare(strict_types=1);

namespace App\Enums;

/**
 * Layout of a bulk A4 QR label sheet.
 *
 * Two sizes rather than a configurable grid: a label sheet is printed onto
 * physical stationery (pre-cut label sheets or plain paper cut by hand
 * afterwards), so the choice that actually matters to a user is "small
 * labels, more per sheet" versus "large labels, easier to read and scan from
 * a distance" — not an arbitrary column/row count nothing will line up with
 * anyway once support for pre-cut Avery-style sheets is considered.
 */
enum QrLabelTemplate: string
{
    case Standard = 'standard';
    case Large = 'large';

    /**
     * @return array<string, string> value => label, for select inputs
     */
    public static function options(): array
    {
        return array_reduce(
            self::cases(),
            static fn (array $carry, self $case): array => $carry + [$case->value => $case->label()],
            [],
        );
    }

    public function label(): string
    {
        return match ($this) {
            self::Standard => 'Standard — 24 per sheet (3 × 8)',
            self::Large => 'Large — 10 per sheet (2 × 5)',
        };
    }

    public function columns(): int
    {
        return match ($this) {
            self::Standard => 3,
            self::Large => 2,
        };
    }

    public function rows(): int
    {
        return match ($this) {
            self::Standard => 8,
            self::Large => 5,
        };
    }

    public function perSheet(): int
    {
        return $this->columns() * $this->rows();
    }

    /**
     * Pixel size the embedded QR PNG is rendered at — large enough to stay
     * sharp at each template's print size without needlessly bloating the
     * PDF for the smaller one.
     */
    public function qrSize(): int
    {
        return match ($this) {
            self::Standard => 220,
            self::Large => 320,
        };
    }
}
