<?php

namespace App\Modules\Inventory\DTOs;

final class ItemCategoryWriteData
{
    public function __construct(
        public readonly string $name,
        public readonly ?int $parentId,
        public readonly int $sortOrder,
    ) {}

    /**
     * @param  array<string, mixed>  $validated
     */
    public static function fromValidated(array $validated): self
    {
        return new self(
            name: (string) $validated['name'],
            parentId: ! empty($validated['parent_id']) ? (int) $validated['parent_id'] : null,
            sortOrder: isset($validated['sort_order']) ? (int) $validated['sort_order'] : 0,
        );
    }
}
