<?php

declare(strict_types=1);

namespace App\Observers;

use App\Models\GroupReleaseContributor;
use App\Services\Profile\CreatorJourneyService;

final class GroupReleaseContributorObserver
{
    public function __construct(private readonly CreatorJourneyService $journeys)
    {
    }

    public function created(GroupReleaseContributor $contributor): void
    {
        $this->journeys->requestRebuild((int) $contributor->user_id);
    }

    public function updated(GroupReleaseContributor $contributor): void
    {
        $this->journeys->requestRebuild((int) $contributor->user_id);

        if ($contributor->wasChanged('user_id')) {
            $this->journeys->requestRebuild((int) $contributor->getOriginal('user_id'));
        }
    }

    public function deleted(GroupReleaseContributor $contributor): void
    {
        $this->journeys->requestRebuild((int) $contributor->user_id);
    }

    public function forceDeleted(GroupReleaseContributor $contributor): void
    {
        $this->journeys->requestRebuild((int) $contributor->user_id);
    }
}