<?php

declare(strict_types=1);

namespace {{DummyTestNameSpace}};

use Tests\TestCase;
use App\Models\User;
use {{DummyModelWithNameSpace}};
use Illuminate\Foundation\Testing\RefreshDatabase;

class {{DummyTest}} extends TestCase
{
    use  RefreshDatabase;

    protected string $endpoint = '{{baseUrlPrefix}}/{{dummies}}';
    protected string $tableName = '{{dummies}}';

    public function setUp(): void
    {
        parent::setUp();
    }

    public function testCreate{{Dummy}}(): void
    {
        $this->markTestIncomplete('This test case needs review.');

        $this->actingAs(User::factory()->create());

        $payload = {{DummyModel}}::factory()->make([])->toArray();

        $this->json('POST', $this->endpoint, $payload)
             ->assertStatus(201)
             ->assertSee($payload['name']);

        $this->assertDatabaseHas($this->tableName, ['id' => 1]);
    }

    public function testViewAll{{Dummies}}Successfully(): void
    {
        $this->markTestIncomplete('This test case needs review.');

        $this->actingAs(User::factory()->create());

        {{DummyModel}}::factory(5)->create();

        $this->json('GET', $this->endpoint)
             ->assertStatus(200)
             ->assertJsonCount(5, 'data')
             ->assertSee({{DummyModel}}::find(rand(1, 5))->name);
    }

    public function testViewAll{{Dummies}}ByFooFilter(): void
    {
        $this->markTestIncomplete('This test case needs review.');

        $this->actingAs(User::factory()->create());

        {{DummyModel}}::factory(5)->create();

        $this->json('GET', $this->endpoint.'?foo=1')
             ->assertStatus(200)
             ->assertSee('foo')
             ->assertDontSee('foo');
    }

    public function testsCreate{{Dummy}}Validation(): void
    {
        $this->markTestIncomplete('This test case needs review.');

        $this->actingAs(User::factory()->create());

        $data = [
        ];

        $this->json('post', $this->endpoint, $data)
             ->assertStatus(422);
    }

    public function testView{{Dummy}}Data(): void
    {
        $this->markTestIncomplete('This test case needs review.');

        $this->actingAs(User::factory()->create());

        {{DummyModel}}::factory()->create();

        $this->json('GET', $this->endpoint.'/1')
             ->assertSee({{DummyModel}}::first()->name)
             ->assertStatus(200);
    }

    public function testUpdate{{Dummy}}(): void
    {
        $this->markTestIncomplete('This test case needs review.');

        $this->actingAs(User::factory()->create());

        {{DummyModel}}::factory()->create();

        $payload = [
            'name' => 'Random'
        ];

        $this->json('PUT', $this->endpoint.'/1', $payload)
             ->assertStatus(200)
             ->assertSee($payload['name']);
    }

    public function testDelete{{Dummy}}(): void
    {
        $this->markTestIncomplete('This test case needs review.');

        $this->actingAs(User::factory()->create());

        {{DummyModel}}::factory()->create();

        $this->json('DELETE', $this->endpoint.'/1')
             ->assertStatus(204);

        $this->assertEquals(0, {{DummyModel}}::count());
    }
    @if('soft-delete')
    public function testRestore{{Dummy}}(): void
    {
        $this->markTestIncomplete('This test case needs review.');

        $this->actingAs(User::factory()->create());

        {{DummyModel}}::factory()->create();

        $this->json('DELETE', $this->endpoint.'/1')
             ->assertStatus(204);

        $this->json('GET', $this->endpoint.'/1/restore')
             ->assertStatus(200);

        $this->assertDatabaseHas($this->tableName, [
            'id'         => 1,
            'deleted_at' => null,
        ]);
    }

    public function testPermanent{{Dummy}}(): void
    {
        $this->markTestIncomplete('This test case needs review.');

        $this->actingAs(User::factory()->create());

        {{DummyModel}}::factory()->create();

        $this->json('DELETE', $this->endpoint.'/1')
             ->assertStatus(204);

        $this->json('DELETE', $this->endpoint.'/1/permanent-delete')
             ->assertStatus(204);

        $this->assertDatabaseMissing($this->tableName, ['id' => 1]);
    }@endif('soft-delete')
}
