<?php

namespace App\Services\Publishing;

use App\Models\ArticlePublication;

/**
 * Publishing has three outcomes, not two: it can succeed, be deliberately
 * skipped, or fail. Returning a bare null for the last two made every skip
 * surface as a publish failure (#123).
 */
class PublishOutcome
{
    private function __construct(
        public readonly ?ArticlePublication $publication,
        public readonly bool $skipped,
        public readonly ?string $reason = null,
    ) {}

    public static function published(ArticlePublication $publication): self
    {
        return new self($publication, false);
    }

    public static function skipped(string $reason): self
    {
        return new self(null, true, $reason);
    }

    public static function failure(string $reason): self
    {
        return new self(null, false, $reason);
    }

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

    public function wasSkipped(): bool
    {
        return $this->skipped;
    }

    public function failed(): bool
    {
        return ! $this->succeeded() && ! $this->skipped;
    }
}
