import 'package:flutter_test/flutter_test.dart';
import 'package:ot_movil/models/work_order.dart';

void main() {
  test('calcula la evidencia total de una orden', () {
    final now = DateTime(2026, 7, 24);
    final order = WorkOrder(
      id: 'ot-1',
      title: 'Mantención preventiva',
      createdAt: now,
      updatedAt: now,
      status: WorkOrderStatus.completed,
      laborCost: 25000,
      details: const WorkOrderDetails(
        client: 'María Soto',
        phone: '+56 9 1234 5678',
        address: 'Los Aromos 120',
      ),
      tasks: const [
        WorkTask(
          id: 'task-1',
          title: 'Lubricar equipo',
          observation: 'Equipo lubricado.',
          position: 0,
          parts: [
            TaskPart(id: 'part-1', name: 'Válvula', price: 7500),
            TaskPart(id: 'part-2', name: 'Flexible', price: 3500),
          ],
          photos: [
            TaskPhoto(
              id: 'before-1',
              path: '/before.jpg',
              kind: PhotoKind.before,
            ),
            TaskPhoto(id: 'after-1', path: '/after.jpg', kind: PhotoKind.after),
          ],
        ),
      ],
    );

    expect(order.isCompleted, isTrue);
    expect(order.totalPhotos, 2);
    expect(order.tasks.single.partsTotal, 11000);
    expect(order.totalPartsCost, 11000);
    expect(order.laborCost, 25000);
    expect(order.totalCost, 36000);
    expect(order.copyWith(laborCost: 30000).totalCost, 41000);
    expect(order.details.isComplete, isTrue);
    expect(order.tasks.single.beforePhotos, hasLength(1));
    expect(order.tasks.single.afterPhotos, hasLength(1));
  });

  test(
    'un estado desconocido de base de datos se interpreta como borrador',
    () {
      expect(WorkOrderStatus.fromDatabase('desconocido'), WorkOrderStatus.open);
    },
  );
}
