<?php
declare(strict_types=1);

namespace PpPhp\Core\Designer\DragDrop;

final class DesignerDragOperation
{
    public function __construct(
        private readonly string $operation,
        private readonly array $payload,
        private readonly array $target,
        private readonly bool $success = true,
        private readonly string $createdAt = ''
    ) {}

    public static function create(string $operation, array $payload, array $target, bool $success = true): self
    {
        return new self($operation, $payload, $target, $success, date('c'));
    }

    public function toArray(): array
    {
        return [
            'operation' => $this->operation,
            'payload' => $this->payload,
            'target' => $this->target,
            'success' => $this->success,
            'createdAt' => $this->createdAt !== '' ? $this->createdAt : date('c'),
        ];
    }
}
