<?php

namespace App\Framework\Smartlinks\Actions;

final readonly class ActionResult
{
    public function __construct(
        public bool $success,
        public string $message = '',
        public array $data = [],
        public ?string $redirectUrl = null,
        public array $errors = []
    ) {}

    public static function success(string $message = '', array $data = [], ?string $redirectUrl = null): self
    {
        return new self(
            success: true,
            message: $message,
            data: $data,
            redirectUrl: $redirectUrl
        );
    }

    public static function failure(string $message, array $errors = []): self
    {
        return new self(
            success: false,
            message: $message,
            errors: $errors
        );
    }

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

    public function hasRedirect(): bool
    {
        return $this->redirectUrl !== null;
    }
}
