<?php

namespace App\DTO;

readonly class MachineDTO
{
    public function __construct(
        public string $name,
        public string $machineNumber = '1',
        public ?string $password = null,
        public ?string $cloudId = null,
        public string $status = 'offline',
        public string $personnelTarget = 'both',
        public ?string $lastSync = null
    ) {}


    public static function fromArray(array $data): self
    {
        return new self(
            name: $data['name'],
            machineNumber: $data['machine_number'] ?? '1',
            password: $data['password'] ?? null,
            cloudId: $data['cloud_id'] ?? null,
            status: $data['status'] ?? 'offline',
            personnelTarget: $data['personnel_target'] ?? 'both',
            lastSync: $data['last_sync'] ?? null
        );
    }

    public function toArray(): array
    {
        return [
            'name' => $this->name,
            'machine_number' => $this->machineNumber,
            'password' => $this->password,
            'cloud_id' => $this->cloudId,
            'status' => $this->status,
            'personnel_target' => $this->personnelTarget,
            'last_sync' => $this->lastSync,
        ];
    }
}
