<?php

namespace Modules\Booking\Enums;

/**
 * Which external actor created the booking (domain.md §8).
 */
enum BookingChannel: string
{
    case MiniApp = 'kbz_miniapp';
    case Android = 'android';
    case Ios = 'ios';
    case Web = 'web';
    case Agent = 'agent';
    case Admin = 'admin';

    /**
     * Resolve the client's channel from its `Device-Type` header, defaulting
     * to MiniApp when the header is missing or unrecognized. Agent/Admin are
     * deliberately excluded from what a header can select — those two are
     * derived from how the request authenticated (FastAPI JWT, Filament),
     * never a client-supplied value, so a customer can't spoof one via the
     * header.
     */
    public static function fromDeviceTypeHeader(?string $deviceType): self
    {
        $channel = self::tryFrom((string) $deviceType);

        if ($channel === null || in_array($channel, [self::Agent, self::Admin], true)) {
            return self::MiniApp;
        }

        return $channel;
    }
}
