<?php

declare(strict_types=1);

namespace App\DTOs\Import;

readonly class ReportRowDto
{
    public function __construct(
        public string $employeeNumber,
        public ?string $reportDate,
        public ?string $title,
        public ?string $description,
        public ?string $severity,
    ) {}

    /**
     * @param  array<string, mixed>  $row
     */
    public static function fromMappedRow(array $row): self
    {
        return new self(
            employeeNumber: (string) ($row['employee_number'] ?? ''),
            reportDate: self::nullableString($row['report_date'] ?? null),
            title: self::nullableString($row['title'] ?? null),
            description: self::nullableString($row['description'] ?? null),
            severity: self::nullableString($row['severity'] ?? null),
        );
    }

    private static function nullableString(mixed $value): ?string
    {
        if ($value === null || $value === '') {
            return null;
        }

        return (string) $value;
    }
}
