<?php

declare(strict_types=1);

namespace Drupal\conductor\Hook;

use Drupal\conductor\DraftCleanup;
use Drupal\conductor\Repository\DraftRepositoryInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Hook\Attribute\Hook;

final readonly class ConductorHooks {

  public function __construct(
    private DraftRepositoryInterface $draftRepository,
    private DraftCleanup $draftCleanup,
  ) {
  }

  #[Hook('entity_delete')]
  public function entityDelete(EntityInterface $entity): void {
    $this->draftRepository->deleteDraft($entity->getEntityTypeId(), (int) $entity->id());
  }

  #[Hook('cron')]
  public function cron(): void {
    // Cleanup unlinked drafts
    $this->draftCleanup->run();
  }

}
