<?php

namespace App\Modules\HR\Attendance\Infrastructure;

use App\Modules\HR\Attendance\Contracts\BiometricPayloadNormalizer;
use App\Modules\HR\Attendance\Support\BiometricApiType;

class GenericBiometricNormalizer implements BiometricPayloadNormalizer
{
    public function normalize(array $raw): ?array
    {
        $fp = $raw['employee_fingerprint_id'] ?? $raw['fingerprint_id'] ?? null;
        $time = $raw['punch_time'] ?? $raw['punched_at'] ?? null;
        if (! is_string($fp) || $fp === '' || ! is_string($time) || $time === '') {
            return null;
        }

        return [
            'employee_fingerprint_id' => $fp,
            'punch_time' => $time,
            'meta' => $raw,
        ];
    }

    public function supports(string $apiType): bool
    {
        return in_array($apiType, [
            BiometricApiType::GENERIC,
            BiometricApiType::ZKTECO,
            BiometricApiType::SUPREMA,
            BiometricApiType::REST_WEBHOOK,
        ], true);
    }
}
