<?php

declare(strict_types=1);

namespace App\Enums;

/**
 * Kind of document attached to an asset.
 *
 * An asset can carry any number of these — a purchase invoice, a PO, a
 * delivery challan, a warranty document, or anything else worth keeping on
 * file — which is why they live in their own table rather than as columns
 * on `assets`. See AssetDocument.
 */
enum AssetDocumentType: string implements HasBadge
{
    case Invoice = 'invoice';
    case PurchaseOrder = 'purchase_order';
    case DeliveryChallan = 'delivery_challan';
    case WarrantyDocument = 'warranty_document';
    case Other = 'other';

    /**
     * @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::Invoice => 'Invoice',
            self::PurchaseOrder => 'Purchase Order',
            self::DeliveryChallan => 'Delivery Challan',
            self::WarrantyDocument => 'Warranty Document',
            self::Other => 'Other',
        };
    }

    public function color(): string
    {
        return match ($this) {
            self::Invoice => 'primary',
            self::PurchaseOrder => 'info',
            self::DeliveryChallan => 'secondary',
            self::WarrantyDocument => 'warning',
            self::Other => 'secondary',
        };
    }

    public function icon(): string
    {
        return match ($this) {
            self::Invoice => 'receipt',
            self::PurchaseOrder => 'file-earmark-text',
            self::DeliveryChallan => 'truck',
            self::WarrantyDocument => 'shield-check',
            self::Other => 'file-earmark',
        };
    }
}
