<?php

namespace App\Modules\HR\Employees\DTOs;

final readonly class EmployeeAssetWriteData
{
    public function __construct(
        public string $assetCode,
        public string $assetName,
        public ?string $category,
        public string $assignedAt,
        public ?string $returnedAt,
        public string $status,
        public ?string $notes,
        public ?int $externalAssetId,
    ) {}

    /** @param  array<string, mixed>  $data */
    public static function fromValidated(array $data): self
    {
        return new self(
            assetCode: (string) $data['asset_code'],
            assetName: (string) $data['asset_name'],
            category: isset($data['category']) ? (string) $data['category'] : null,
            assignedAt: (string) $data['assigned_at'],
            returnedAt: isset($data['returned_at']) ? (string) $data['returned_at'] : null,
            status: (string) $data['status'],
            notes: isset($data['notes']) ? (string) $data['notes'] : null,
            externalAssetId: isset($data['external_asset_id']) ? (int) $data['external_asset_id'] : null,
        );
    }

    /** @return array<string, mixed> */
    public function toArray(): array
    {
        return [
            'asset_code' => $this->assetCode,
            'asset_name' => $this->assetName,
            'category' => $this->category,
            'assigned_at' => $this->assignedAt,
            'returned_at' => $this->returnedAt,
            'status' => $this->status,
            'notes' => $this->notes,
            'external_asset_id' => $this->externalAssetId,
        ];
    }
}
