<?php

declare(strict_types=1);

namespace App\Tests\Domain\Shared\Application\CommandHandler;

use App\Domain\Scraping\Domain\Model\ScrapingJob;
use App\Domain\Shared\Application\Command\DeleteJob;
use App\Domain\Shared\Application\CommandHandler\DeleteJobHandler;
use App\Domain\Shared\Domain\Exception\JobNotFoundException;
use App\Tests\Domain\Shared\Adapter\InMemoryJobRepository;
use PHPUnit\Framework\TestCase;

class DeleteJobHandlerTest extends TestCase
{
    private InMemoryJobRepository $repository;
    private DeleteJobHandler $handler;

    protected function setUp(): void
    {
        $this->repository = new InMemoryJobRepository();
        $this->handler = new DeleteJobHandler($this->repository);
    }

    public function test_it_deletes_existing_job(): void
    {
        $job = new ScrapingJob('job-1', 'manga-1', 1.0, 'source-1');
        $this->repository->save($job);

        $this->handler->handle(new DeleteJob('job-1'));

        $this->assertNull($this->repository->get('job-1'));
    }

    public function test_it_throws_when_job_not_found(): void
    {
        $this->expectException(JobNotFoundException::class);

        $this->handler->handle(new DeleteJob('non-existent-id'));
    }
}
