<?php

declare(strict_types=1);

namespace App\Tests\Api;

use App\Tests\AbstractApiTestCase;

/**
 * @internal
 */
class ValidationTest extends AbstractApiTestCase
{
    public function testConstructeurRequiresName(): void
    {
        $client = $this->createGestionnaireClient();
        $client->request('POST', '/api/constructeurs', [
            'headers' => ['Content-Type' => 'application/ld+json'],
            'json'    => ['email' => 'no-name@test.com'],
        ]);

        $this->assertResponseStatusCodeSame(422);
    }

    public function testSiteRequiresName(): void
    {
        $client = $this->createGestionnaireClient();
        $client->request('POST', '/api/sites', [
            'headers' => ['Content-Type' => 'application/ld+json'],
            'json'    => ['contactCity' => 'Paris'],
        ]);

        $this->assertResponseStatusCodeSame(422);
    }

    public function testMachineRequiresSite(): void
    {
        $client = $this->createGestionnaireClient();
        $client->request('POST', '/api/machines', [
            'headers' => ['Content-Type' => 'application/ld+json'],
            'json'    => ['name' => 'Machine sans site'],
        ]);

        $this->assertResponseStatusCodeSame(422);
    }

    public function testProfileRequiresFirstAndLastName(): void
    {
        $client = $this->createAdminClient();
        $client->request('POST', '/api/profiles', [
            'headers' => ['Content-Type' => 'application/ld+json'],
            'json'    => ['email' => 'missing@names.com'],
        ]);

        $this->assertResponseStatusCodeSame(422);
    }

    public function testDuplicateConstructeurName(): void
    {
        $this->createConstructeur('Siemens');

        $client = $this->createGestionnaireClient();
        $client->request('POST', '/api/constructeurs', [
            'headers' => ['Content-Type' => 'application/ld+json'],
            'json'    => ['name' => 'Siemens'],
        ]);

        $this->assertResponseStatusCodeSame(422);
    }
}
