import 'package:equatable/equatable.dart';
import 'package:krow_domain/krow_domain.dart';

enum OneTimeOrderStatus { initial, loading, success, failure }

class OneTimeOrderState extends Equatable {
  const OneTimeOrderState({
    required this.date,
    required this.location,
    required this.positions,
    this.status = OneTimeOrderStatus.initial,
    this.errorMessage,
    this.vendors = const <Vendor>[],
    this.selectedVendor,
    this.roles = const <OneTimeOrderRoleOption>[],
  });

  factory OneTimeOrderState.initial() {
    return OneTimeOrderState(
      date: DateTime.now(),
      location: '',
      positions: const <OneTimeOrderPosition>[
        OneTimeOrderPosition(role: '', count: 1, startTime: '', endTime: ''),
      ],
      vendors: const <Vendor>[],
      roles: const <OneTimeOrderRoleOption>[],
    );
  }
  final DateTime date;
  final String location;
  final List<OneTimeOrderPosition> positions;
  final OneTimeOrderStatus status;
  final String? errorMessage;
  final List<Vendor> vendors;
  final Vendor? selectedVendor;
  final List<OneTimeOrderRoleOption> roles;

  OneTimeOrderState copyWith({
    DateTime? date,
    String? location,
    List<OneTimeOrderPosition>? positions,
    OneTimeOrderStatus? status,
    String? errorMessage,
    List<Vendor>? vendors,
    Vendor? selectedVendor,
    List<OneTimeOrderRoleOption>? roles,
  }) {
    return OneTimeOrderState(
      date: date ?? this.date,
      location: location ?? this.location,
      positions: positions ?? this.positions,
      status: status ?? this.status,
      errorMessage: errorMessage ?? this.errorMessage,
      vendors: vendors ?? this.vendors,
      selectedVendor: selectedVendor ?? this.selectedVendor,
      roles: roles ?? this.roles,
    );
  }

  @override
  List<Object?> get props => <Object?>[
    date,
    location,
    positions,
    status,
    errorMessage,
    vendors,
    selectedVendor,
    roles,
  ];
}

class OneTimeOrderRoleOption extends Equatable {
  const OneTimeOrderRoleOption({
    required this.id,
    required this.name,
    required this.costPerHour,
  });

  final String id;
  final String name;
  final double costPerHour;

  @override
  List<Object?> get props => <Object?>[id, name, costPerHour];
}
