<?php

namespace App\Modules\HR\Employees\DTOs;

final readonly class EmployeeAddressWriteData
{
    public function __construct(
        public ?int $countryId,
        public ?int $regionId,
        public ?int $cityId,
        public ?string $street,
        public ?string $buildingNumber,
        public ?string $locationLink,
    ) {}

    /**
     * @param  array<string, mixed>  $data
     */
    public static function fromValidated(array $data): self
    {
        return new self(
            countryId: ! empty($data['address_country_id']) ? (int) $data['address_country_id'] : null,
            regionId: ! empty($data['address_region_id']) ? (int) $data['address_region_id'] : null,
            cityId: ! empty($data['address_city_id']) ? (int) $data['address_city_id'] : null,
            street: isset($data['address_street']) ? (string) $data['address_street'] : null,
            buildingNumber: isset($data['address_building_number'])
                ? (string) $data['address_building_number']
                : null,
            locationLink: isset($data['address_location_link'])
                ? (string) $data['address_location_link']
                : null,
        );
    }
}
