import 'package:krow_domain/krow_domain.dart';

/// Mock implementation of order-related data operations.
///
/// This class simulates backend responses for order types and order creation.
/// It is used by the feature-level repository implementations.
class OrderRepositoryMock {
  /// Returns a list of available [OrderType]s.
  Future<List<OrderType>> getOrderTypes() async {
    await Future<void>.delayed(const Duration(milliseconds: 500));
    return const <OrderType>[
      OrderType(
        id: 'rapid',
        titleKey: 'client_create_order.types.rapid',
        descriptionKey: 'client_create_order.types.rapid_desc',
      ),
      OrderType(
        id: 'one-time',
        titleKey: 'client_create_order.types.one_time',
        descriptionKey: 'client_create_order.types.one_time_desc',
      ),
      OrderType(
        id: 'recurring',
        titleKey: 'client_create_order.types.recurring',
        descriptionKey: 'client_create_order.types.recurring_desc',
      ),
      OrderType(
        id: 'permanent',
        titleKey: 'client_create_order.types.permanent',
        descriptionKey: 'client_create_order.types.permanent_desc',
      ),
    ];
  }

  /// Simulates creating a one-time order.
  Future<void> createOneTimeOrder(OneTimeOrder order) async {
    await Future<void>.delayed(const Duration(milliseconds: 800));
  }

  /// Simulates creating a rapid order.
  Future<void> createRapidOrder(String description) async {
    await Future<void>.delayed(const Duration(seconds: 1));
  }

  /// Returns a mock list of client orders.
  Future<List<OrderItem>> getOrders() async {
    await Future<void>.delayed(const Duration(milliseconds: 500));
    return <OrderItem>[
      OrderItem(
        id: '1',
        orderId: 'order_1',
        title: 'Server - Wedding',
        clientName: 'Grand Plaza Hotel',
        status: 'filled',
        date: DateTime.now()
            .add(const Duration(days: 1))
            .toIso8601String()
            .split('T')[0],
        startTime: '16:00',
        endTime: '23:00',
        location: 'Grand Plaza Hotel, 123 Main St',
        locationAddress: 'Grand Plaza Hotel, 123 Main St',
        filled: 10,
        workersNeeded: 10,
        hourlyRate: 22.0,
        confirmedApps: List<Map<String, dynamic>>.generate(
          10,
          (int index) => <String, dynamic>{
            'id': 'app_$index',
            'worker_id': 'w_$index',
            'worker_name': 'Worker ${String.fromCharCode(65 + index)}',
            'status': 'confirmed',
            'check_in_time': index < 5 ? '15:55' : null,
          },
        ),
      ),
      OrderItem(
        id: '2',
        orderId: 'order_2',
        title: 'Bartender - Private Event',
        clientName: 'Taste of the Town',
        status: 'open',
        date: DateTime.now()
            .add(const Duration(days: 1))
            .toIso8601String()
            .split('T')[0],
        startTime: '18:00',
        endTime: '02:00',
        location: 'Downtown Loft, 456 High St',
        locationAddress: 'Downtown Loft, 456 High St',
        filled: 4,
        workersNeeded: 5,
        hourlyRate: 28.0,
        confirmedApps: List<Map<String, dynamic>>.generate(
          4,
          (int index) => <String, dynamic>{
            'id': 'app_b_$index',
            'worker_id': 'w_b_$index',
            'worker_name': 'Bartender ${index + 1}',
            'status': 'confirmed',
          },
        ),
      ),
      OrderItem(
        id: '3',
        orderId: 'order_3',
        title: 'Event Staff',
        clientName: 'City Center',
        status: 'in_progress',
        date: DateTime.now().toIso8601String().split('T')[0],
        startTime: '08:00',
        endTime: '16:00',
        location: 'Convention Center, 789 Blvd',
        locationAddress: 'Convention Center, 789 Blvd',
        filled: 15,
        workersNeeded: 15,
        hourlyRate: 20.0,
        confirmedApps: List<Map<String, dynamic>>.generate(
          15,
          (int index) => <String, dynamic>{
            'id': 'app_c_$index',
            'worker_id': 'w_c_$index',
            'worker_name': 'Staff ${index + 1}',
            'status': 'confirmed',
            'check_in_time': '07:55',
          },
        ),
      ),
      OrderItem(
        id: '4',
        orderId: 'order_4',
        title: 'Coat Check',
        clientName: 'The Met Museum',
        status: 'completed',
        date: DateTime.now()
            .subtract(const Duration(days: 1))
            .toIso8601String()
            .split('T')[0],
        startTime: '17:00',
        endTime: '22:00',
        location: 'The Met Museum, 1000 5th Ave',
        locationAddress: 'The Met Museum, 1000 5th Ave',
        filled: 2,
        workersNeeded: 2,
        hourlyRate: 18.0,
        confirmedApps: List<Map<String, dynamic>>.generate(
          2,
          (int index) => <String, dynamic>{
            'id': 'app_d_$index',
            'worker_id': 'w_d_$index',
            'worker_name': 'Checker ${index + 1}',
            'status': 'confirmed',
            'check_in_time': '16:50',
          },
        ),
      ),
    ];
  }
}
