<?php

namespace Tests\Feature\Tenant;

use App\Models\ClinicalNote;
use App\Models\Customer;
use App\Models\User;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class ClinicalHistoryFeatureTest extends TestCase
{
    use RefreshDatabase;

    public function test_company_admin_can_update_clinical_history_and_add_notes(): void
    {
        $this->seed(DatabaseSeeder::class);

        $user = User::where('email', 'admin@barberia-demo.test')->firstOrFail();
        $customer = Customer::firstOrFail();

        $this->actingAs($user)
            ->put(route('tenant.clinical-histories.update', $customer), [
                'allergies' => 'Penicilina',
                'skin_type' => 'Sensible',
                'initial_diagnosis' => 'Control inicial',
            ])
            ->assertRedirect();

        $this->assertDatabaseHas('clinical_histories', [
            'customer_id' => $customer->id,
            'skin_type' => 'Sensible',
        ]);

        $this->actingAs($user)
            ->post(route('tenant.clinical-histories.notes.store', $customer), [
                'title' => 'Seguimiento',
                'content' => 'Evolución satisfactoria.',
                'tags' => 'control, piel',
            ])
            ->assertRedirect();

        $this->assertSame('Seguimiento', ClinicalNote::firstOrFail()->title);
    }
}
