<?php

namespace Tests\Feature;

use App\Models\ClientRequest;
use App\Models\Service;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class OneTimeServiceOrderTest extends TestCase
{
    use RefreshDatabase;

    public function test_guest_can_order_service_and_get_one_time_client_portal(): void
    {
        $service = Service::create(['name' => 'Logo Design', 'slug' => 'logo-design', 'description' => 'Logo service', 'status' => 'active']);

        $this->post('/order-service', [
            'service_id' => $service->id,
            'name' => 'Random Buyer',
            'email' => 'random-buyer@mgg.test',
            'phone' => '03068665907',
            'password' => 'password',
            'password_confirmation' => 'password',
            'title' => 'Need a logo',
            'details' => 'Please create a modern logo.',
        ])->assertRedirect('/client/requests');

        $this->assertDatabaseHas('users', [
            'email' => 'random-buyer@mgg.test',
            'role' => 'client',
            'client_type' => 'one_time',
        ]);
        $this->assertDatabaseHas('client_requests', [
            'service_id' => $service->id,
            'request_type' => 'one_time_order',
            'title' => 'Need a logo',
            'status' => 'pending',
        ]);
    }

    public function test_one_time_client_dashboard_hides_monthly_plan_panel(): void
    {
        $client = User::create([
            'name' => 'One Time Client',
            'email' => 'one-time-client@mgg.test',
            'password' => 'password',
            'role' => 'client',
            'client_type' => 'one_time',
        ]);

        ClientRequest::create([
            'user_id' => $client->id,
            'request_type' => 'one_time_order',
            'title' => 'Poster order',
            'details' => 'One poster',
            'status' => 'pending',
        ]);

        $this->actingAs($client)->get('/client/dashboard')
            ->assertOk()
            ->assertSee('Service Orders')
            ->assertDontSee('My Plan');
    }
}
