<?php

namespace App\ScheduledTasks;

class ActionResult
{
    public const STATUS_COMPLETED = 'completed';
    public const STATUS_FAILED = 'failed';
    public const STATUS_SKIPPED = 'skipped';

    public function __construct(
        public readonly string $status,
        public readonly string $message = '',
        public readonly array $stats = [],
    ) {
    }

    public static function completed(string $message = '', array $stats = []): self
    {
        return new self(self::STATUS_COMPLETED, $message, $stats);
    }

    public static function failed(string $message, array $stats = []): self
    {
        return new self(self::STATUS_FAILED, $message, $stats);
    }

    public static function skipped(string $message): self
    {
        return new self(self::STATUS_SKIPPED, $message);
    }

    public function failedStatus(): bool
    {
        return $this->status === self::STATUS_FAILED;
    }

    public function toArray(): array
    {
        return [
            'status' => $this->status,
            'message' => $this->message,
            'stats' => $this->stats,
        ];
    }
}
