<?php

use App\Models\Role;
use App\Models\User;

test('administrador puede ver cualquier trabajo', function () {
    $user = createUserWithRole(Role::ADMINISTRATOR_NAME);
    $work = createWorkWithUserAssignments();

    expect($user->can('view', $work))->toBeTrue();
});

test('coordinador puede ver cualquier trabajo', function () {
    $user = createUserWithRole(Role::COORDINATOR_NAME);
    $work = createWorkWithUserAssignments();

    expect($user->can('view', $work))->toBeTrue();
});

test('técnico solo puede ver su trabajo asignado', function () {
    $tech = createUserWithRole(Role::TECHNICIAN_NAME);
    $other = User::factory()->create();
    $workOwn = createWorkWithUserAssignments(technician: $tech);
    $workOther = createWorkWithUserAssignments(technician: $other);

    expect($tech->can('view', $workOwn))->toBeTrue();
    expect($tech->can('view', $workOther))->toBeFalse();
});

test('noc puede ver cualquier trabajo', function () {
    $noc = createUserWithRole(Role::NOC_NAME);
    $work = createWorkWithUserAssignments();

    expect($noc->can('view', $work))->toBeTrue();
});

test('coordinador puede actualizar campos de coordinación', function () {
    $user = createUserWithRole(Role::COORDINATOR_NAME);
    $work = createWorkWithUserAssignments();

    expect($user->can('updateCoordinatorFields', $work))->toBeTrue();
});

test('técnico no puede actualizar campos de coordinación', function () {
    $tech = createUserWithRole(Role::TECHNICIAN_NAME);
    $work = createWorkWithUserAssignments(technician: $tech);

    expect($tech->can('updateCoordinatorFields', $work))->toBeFalse();
});

test('técnico asignado puede actualizar su cierre en campo', function () {
    $tech = createUserWithRole(Role::TECHNICIAN_NAME);
    $work = createWorkWithUserAssignments(technician: $tech);

    expect($tech->can('updateTechnicianFields', $work))->toBeTrue();
});

test('noc puede actualizar seguimiento', function () {
    $noc = createUserWithRole(Role::NOC_NAME);
    $work = createWorkWithUserAssignments();

    expect($noc->can('updateNocFields', $work))->toBeTrue();
});
