<?php
declare(strict_types=1);

namespace PpPhp\Core\Designer\Layout;

final class DesignerLayoutOperation
{
    public function __construct(private readonly string $operation, private readonly array $payload = [], private readonly bool $success = true, private readonly string $message = '', private readonly string $createdAt = '') {}

    public static function success(string $operation, array $payload = [], string $message = 'operation completed'): self
    {
        return new self($operation, $payload, true, $message, date('c'));
    }

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