<?php

use App\Models\Usuario;
use App\Services\ShipMarketService;

it('redirects solicitante users from dashboard to ship market', function (): void {
    $user = new Usuario(['cargo' => 'Solicitante', 'tipo' => 7]);
    $user->id = 9001;

    $response = $this->actingAs($user)->get(route('dashboard'));

    $response->assertRedirect(route('ship-market.index'));
});

it('allows solicitante users to access the ship market test page', function (): void {
    $user = new Usuario(['cargo' => 'Solicitante', 'tipo' => 7]);
    $user->id = 9002;

    $service = \Mockery::mock(ShipMarketService::class);
    $service->shouldReceive('cartQuantities')->once()->andReturn([]);
    $service->shouldReceive('buildCatalogData')->once()->andReturn([
        'filters' => ['q' => '', 'tipo' => 0],
        'typeOptions' => [],
        'items' => [],
        'totals' => ['bienes_disponibles' => 0, 'unidades_disponibles' => 0],
    ]);
    $service->shouldReceive('buildCartData')->once()->andReturn([
        'items' => [],
        'summary' => ['lineas' => 0, 'unidades' => 0, 'total_estimado' => 0, 'items_sin_precio' => 0],
        'quantities' => [],
    ]);

    $this->app->instance(ShipMarketService::class, $service);

    $response = $this->actingAs($user)->get(route('ship-market.index'));

    $response->assertOk();
    $response->assertSee('Ship Market');
    $response->assertSee('Objetos disponibles para solicitud');
});

it('allows solicitante users to access the ship market help page', function (): void {
    $user = new Usuario(['cargo' => 'Solicitante', 'tipo' => 7]);
    $user->id = 9004;

    $response = $this->actingAs($user)->get(route('ship-market.help'));

    $response->assertOk();
    $response->assertSee('Ayuda de Ship Market');
    $response->assertSee('Como usar Ship Market');
});

it('blocks solicitante users from reportes and graficas', function (): void {
    $user = new Usuario(['cargo' => 'Solicitante', 'tipo' => 7]);
    $user->id = 9003;

    $this->actingAs($user)
        ->get(route('reportes.index'))
        ->assertRedirect(route('dashboard'));

    $this->actingAs($user)
        ->get(route('graficas.index'))
        ->assertRedirect(route('dashboard'));
});