<?php
declare(strict_types=1);

namespace PpPhp\Core\Designer\DragDrop;

final class DesignerDropResult
{
    public function __construct(
        private readonly bool $success,
        private readonly array $page,
        private readonly string $operation,
        private readonly string $componentId = '',
        private readonly string $message = '',
        private readonly array $meta = []
    ) {}

    public static function success(array $page, string $operation, string $componentId = '', array $meta = []): self
    {
        return new self(true, $page, $operation, $componentId, 'operation completed', $meta);
    }

    public static function failure(array $page, string $operation, string $message, array $meta = []): self
    {
        return new self(false, $page, $operation, '', $message, $meta);
    }

    public function isSuccess(): bool { return $this->success; }
    public function page(): array { return $this->page; }

    public function toArray(): array
    {
        return [
            'success' => $this->success,
            'page' => $this->page,
            'operation' => $this->operation,
            'componentId' => $this->componentId,
            'message' => $this->message,
            'meta' => $this->meta,
        ];
    }
}
