import 'package:flutter/cupertino.dart';

enum DeliveryType {
  DELIVERY,
  PICKUP_FROM_CUST,
  P_AND_D_PICKUP,
  P_AND_D_DELIVERY,
  PICKUP,
  DELIVERY_EVEN_EXC,
}

enum ServiceType {
  WHITE_GLOVES,
  THRESHOLD,
  PICK_UP,
  ROOM_OF_CHOICE,
}

enum ServiceStatus {
  PENDING,
  IN_TRANSIT,
  DELIVERED,
  CANCELLED,
}

class Delivery {
  final String deliveryId;
  final String routeId;
  final String recipientName;
  final String recipientPhone;
  final String addressLine1;
  final String addressLine2;
  final String recipientCity;
  final String recipientState;
  final int recipientZipCode;
  final String recipientCountry;
  final int quantity;
  final String itemName;
  final DeliveryType deliveryType;
  final ServiceType serviceType;
  final ServiceStatus deliveryStatus;
  final String driverNotes;
  final String proofOfDelivery;

  Delivery({
    required this.deliveryId,
    required this.routeId,
    required this.recipientName,
    required this.recipientPhone,
    required this.addressLine1,
    required this.addressLine2,
    required this.recipientCity,
    required this.recipientState,
    required this.recipientZipCode,
    required this.recipientCountry,
    required this.quantity,
    required this.itemName,
    required this.deliveryType,
    required this.serviceType,
    required this.deliveryStatus,
    this.driverNotes = '',
    this.proofOfDelivery = ''
  });

  factory Delivery.fromJson(Map<String, dynamic> json) {
    return Delivery(
      deliveryId: json['delivery_id'],
      routeId: json['route_id'],
      recipientName: json['recipient_name'],
      recipientPhone: json['recipient_phone'],
      addressLine1: json['address_line_1'],
      addressLine2: json['address_line_2'],
      recipientCity: json['recipient_city'],
      recipientState: json['recipient_state'],
      recipientZipCode: json['recipient_zip_code'],
      recipientCountry: json['recipient_country'],
      quantity: json['quantity'],
      itemName: json['item_name'],
      deliveryType: DeliveryType.values.firstWhere( (e) => e.toString().split('.').last == json['delivery_type'], orElse: () => DeliveryType.DELIVERY, ),
      serviceType: ServiceType.values.firstWhere( (e) => e.toString().split('.').last == json['service_type'], orElse: () => ServiceType.ROOM_OF_CHOICE, ),
      deliveryStatus: ServiceStatus.values.firstWhere( (e) => e.toString().split('.').last == json['service_status'], orElse: () => ServiceStatus.PENDING, ),
      driverNotes: json['driver_notes'] ?? '',
      proofOfDelivery: json['proof_of_delivery']
    );
  }


}
