<?php

require_once __DIR__ . '/../../autoload/Controllers/TasksController.php';

use Controllers\TasksController;

function assert_same( $expected, $actual, $message )
{
  if ( $expected !== $actual )
    throw new Exception( $message );
}

function run_tasks_controller_tests()
{
  $clients = [
    [ 'id' => 1, 'firm' => 'ACME', 'tasks' => [ '2026-01' => [] ] ]
  ];
  $settings = [ 'hourly_rate' => 250 ];

  $view_model = TasksController::workTimeViewModel( $clients, $settings );

  assert_same( $clients, $view_model['work_time_clients'], 'Expected work_time_clients to be passed through.' );
  assert_same( $settings, $view_model['settings'], 'Expected settings to be passed through.' );

  assert_same( 5, TasksController::resolveTaskStatusForForm( [ 'id' => null, 'status' => null ] ), 'Expected default form status for new task to be 5 (do zrobienia).' );
  assert_same( 1, TasksController::resolveTaskStatusForForm( [ 'id' => 10, 'status' => 1 ] ), 'Expected existing task form status to be preserved.' );

  assert_same( 5, TasksController::resolveTaskStatusForSave( [ 'id' => null ] ), 'Expected default save status for new task to be 5 (do zrobienia).' );
  assert_same( 3, TasksController::resolveTaskStatusForSave( [ 'id' => 22, 'status' => 3 ] ), 'Expected existing task save status to be preserved.' );

  assert_same( true, TasksController::shouldStopTimerOnStatus( 1 ), 'Expected timer stop on status do sprawdzenia.' );
  assert_same( true, TasksController::shouldStopTimerOnStatus( 2 ), 'Expected timer stop on status zamkniete.' );
  assert_same( true, TasksController::shouldStopTimerOnStatus( 3 ), 'Expected timer stop on status do rozliczenia.' );
  assert_same( false, TasksController::shouldStopTimerOnStatus( 0 ), 'Expected no timer stop on status nowe.' );

  assert_same( true, TasksController::shouldSendStatusChangeEmail( 1 ), 'Expected status email for do sprawdzenia.' );
  assert_same( true, TasksController::shouldSendStatusChangeEmail( 3 ), 'Expected status email for do rozliczenia.' );
  assert_same( false, TasksController::shouldSendStatusChangeEmail( 2 ), 'Expected no status email for zamkniete.' );
}
