<?php
namespace App\Tests\Application\Person;

use App\Entity\Person\Person;
use App\Entity\Access\Access;
use App\Entity\Organization\Organization;
use App\Entity\Organization\Settings;
use App\Entity\Public\PublicEvent;
use App\Enum\Organization\PrincipalTypeEnum;
use App\Enum\Organization\SettingsProductEnum;
use App\Tests\Application\OtWebTestCase;
use App\Tests\Fixture\Factory\Access\AccessFactory;
use App\Tests\Fixture\Factory\Organization\OrganizationFactory;
use App\Tests\Fixture\Factory\Organization\SettingsFactory;
use App\Tests\Fixture\Factory\Person\PersonFactory;
use App\Tests\Fixture\PersonFixtures;
use Zenstruck\Foundry\Factory;
use Zenstruck\Foundry\Proxy;
use App\Enum\Organization\LegalEnum;

class PersonTest extends OtWebTestCase
{
    public function testPersonGet(): void
    {
        $this->loginAs($this->user);

        $this->get('/api/people/' . $this->user->getPerson()->getId());

        $this->validateCollectionSchema(Person::class);

        $this->assertJsonContains([
            '@context' => '/api/contexts/Person',
            '@id' => '/api/people/' . $this->user->getPerson()->getId(),
            '@type' => 'Person',
            'username' => 'username'
        ]);
    }

    public function testPersonGetHasNoRole(): void {

        // User has not the required role
        $this->user->setRoles([]);
        $this->user->save();

        $this->loginAs($this->user);

        $this->get('/api/people/' . $this->user->getPerson()->getId());

        $this->validateCollectionSchema(Person::class, 403);

        $this->assertJsonContains([
            "hydra:description" => "Access Denied."
        ]);
    }

    public function testPersonGetCollection(): void {
        $this->loginAs($this->user);

        $this->get('/api/peoples');

        $this->assertResponseStatusCodeSame(404);
    }

    public function testPersonPut(): void {
        $this->loginAs($this->user);

        $this->put('/api/people/' . $this->user->getPerson()->getId(), []);

        // Expects : 405 Method Not Allowed
        $this->assertResponseStatusCodeSame(405);
    }

    public function testPersonPost(): void {
        $this->loginAs($this->user);

        $this->post('/api/people/' . $this->user->getPerson()->getId(), []);

        // Expects : 405 Method Not Allowed
        $this->assertResponseStatusCodeSame(405);
    }

    public function testPersonDelete(): void {
        $this->loginAs($this->user);

        $this->delete('/api/people/' . $this->user->getPerson()->getId());

        // Expects : 405 Method Not Allowed
        $this->assertResponseStatusCodeSame(405);
    }
}
