package entities

import "time"

type ShipmentStatusLog struct {
	BaseEntity

	CourierTrackingID string
	Status            ShipmentStatus
	CourierStatus     string
	CourierID         int64
	StateText         string
	StateDate         time.Time
}

// FlashExpress update courier webhook

type FlashExpressUpdateCourierWebhookLog struct {
	BaseEntity

	CourierTrackingID     string // An item of CourierTrackingIDs in param model
	TicketPickupID        string
	CurrentTicketPickupID string
	State                 string
	StateText             string
	StateDate             time.Time
	CancelReasonCode      string
	CancelReasonText      string
	CancelOperatorID      string
}
type FlashExpressUpdateCourierWebhookParams struct {
	CourierTrackingIDs    []string // Only add in domain/service
	TicketPickupID        string
	CurrentTicketPickupID string
	State                 string
	StateText             string
	StateDate             time.Time
	CancelReasonCode      string
	CancelReasonText      string
	CancelOperatorID      string
}

/*--------------------------------------------------------------------------------------------------------------------*/

var MappingJTExpressTHStatusToShipmentStatus = map[string]ShipmentStatus{
	"CREATE ORDER":        ShipmentStatusCourierStaffAssigned,
	"PICKED UP":           ShipmentStatusPickedUp,
	"DEPARTURE":           ShipmentStatusOnDelivery,
	"ARRIVAL":             ShipmentStatusOnDelivery,
	"ON DELIVERY":         ShipmentStatusOnDelivery,
	"SELF COLLECTION":     ShipmentStatusOnDelivery,
	"SIGNATURE":           ShipmentStatusDelivered,
	"RETURN":              ShipmentStatusFailedDelivery,
	"RETURN CONFIRMATION": ShipmentStatusFailedDelivery,
	"RETURN SIGNATURE":    ShipmentStatusFailedDelivery,
	"PROBLEMATIC":         ShipmentStatusFailedDelivery,
	"OVERNIGHT":           ShipmentStatusFailedDelivery,
}

var MappingJTExpressSGStatusToShipmentStatus = map[string]ShipmentStatus{
	"PENDING_PICKUP":                ShipmentStatusFulfillmentRequestSent, // Order has been created
	"ASSIGNED_PICKUP":               ShipmentStatusCourierStaffAssigned,   // Driver has been assigned pickup task
	"ACCEPTED_PICKUP":               ShipmentStatusCourierStaffAssigned,   // Driver has accepted pickup task
	"ENROUTE_TO_HUB":                ShipmentStatusPickedUp,               // Driver has picked up the item, and on the way to Hub
	"ARRIVED_AT_HUB":                ShipmentStatusPickedUp,               // Item has been scanned arrived at Hub
	"DEPOSITED":                     ShipmentStatusPickedUp,               // Item has been deposited
	"RETRIEVED":                     ShipmentStatusPickedUp,               // Item has been retrieved by our driver
	"OUT_FOR_DELIVERY":              ShipmentStatusOnDelivery,             // Item has been scanned out for delivery by driver
	"FORWARDED_TO_SHIPPING_PARTNER": ShipmentStatusOnDelivery,             // Item has been forwarded to Shipping Partner
	"COLLECTED":                     ShipmentStatusDelivered,              // Item has been collected by consignee
	"DELIVERED":                     ShipmentStatusDelivered,              // Item has been delivered
	"RETURNED_TO_SENDER":            ShipmentStatusFailedDelivery,         // Item has been returned to sender
	"RETURNED_TO_HUB":               ShipmentStatusFailedDelivery,         // Item has been returned to Hub (due to failed delivery)
	"FAILED_PICKUP":                 ShipmentStatusFailedDelivery,         // Item has failed to be picked up
	"FAILED_DELIVERY":               ShipmentStatusFailedDelivery,         // Item has failed to be delivered
	"FAILED_RTS":                    ShipmentStatusFailedDelivery,         // Item has failed to be returned to sender
	"SCHEDULED_RTS":                 ShipmentStatusFailedDelivery,         // Item has been scheduled to return to sender
	"OUT_FOR_RTS":                   ShipmentStatusFailedDelivery,         // Item has been scanned out for return to sender
	"PARCEL_DISPOSED":               ShipmentStatusFailedDelivery,         // Item has been disposed by J&T
	"PARCEL_LEAKAGE":                ShipmentStatusFailedDelivery,         // Parcel leakage
	"PARCEL_LOST":                   ShipmentStatusFailedDelivery,         // Parcel lost
	"PARCEL_DAMAGED":                ShipmentStatusFailedDelivery,         // Parcel damaged
	"CANCELLED":                     ShipmentStatusCancelled,              // Order has been cancelled
	//"MERCHANT_DROPPED_OFF":          ShipmentStatusCourierStaffAssigned,   // Sellers have dropped their parcels at J&T Points
	//"NO_LOCKER_AVAILABLE":           ShipmentStatusCourierStaffAssigned,   // No locker available after two consecutive days of booking attempts
	//"LOCKER_CANCEL":                 ShipmentStatusCourierStaffAssigned,   // Locker booking has been cancelled
	//"LOCKER_BOOKED":                 ShipmentStatusCourierStaffAssigned,   // Locker compartment has been booked
	//"OVERSTAYED_PARCEL":             ShipmentStatusCourierStaffAssigned,   // Item has become overstayed parcel as it was not collected by consignee within due time
	//"OVERSTAYED_ENROUTE":            ShipmentStatusCourierStaffAssigned,   // Overstayed Item has been pickup by our driver
	//"OVERSTAYED_RETRIEVED":          ShipmentStatusCourierStaffAssigned,   // Overstayed item has been retrieved by our partner
}

var MappingFlashExpressWebhookStatusToShipmentStatus = map[string]ShipmentStatus{
	"1": ShipmentStatusPickedUp,       // Picked up
	"2": ShipmentStatusOnDelivery,     // In transit
	"3": ShipmentStatusOnDelivery,     // On Delivery
	"4": ShipmentStatusOnDelivery,     // Detained
	"5": ShipmentStatusDelivered,      // Delivered
	"6": ShipmentStatusOnDelivery,     // Problematic Processing
	"7": ShipmentStatusFailedDelivery, // Returned
	"8": ShipmentStatusFailedDelivery, // Closed
	"9": ShipmentStatusFailedDelivery, // Cancelled
}

var MappingJTExpressMYStatusToShipmentStatus = map[string]ShipmentStatus{
	"101": ShipmentStatusCourierStaffAssigned,
	"100": ShipmentStatusPickedUp,
	"200": ShipmentStatusDelivered,
	"401": ShipmentStatusFailedDelivery,
	"402": ShipmentStatusFailedDelivery,
	"152": ShipmentStatusFailedDelivery,
}

var MappingKerryExpressTHStatusToShipmentStatus = map[string]ShipmentStatus{
	"READY TO SHIP TO KERRY EXPRESS":                                      ShipmentStatusCourierStaffAssigned,
	"YOUR PARCEL HAS BEEN RECEIVED":                                       ShipmentStatusCourierStaffAssigned,
	"YOUR PARCEL HAS BEEN PICKED UP":                                      ShipmentStatusPickedUp,
	"OUR COURIER IS DELIVERING YOUR PARCEL":                               ShipmentStatusOnDelivery,
	"PENDING FOR RE-DELIVERY":                                             ShipmentStatusOnDelivery,
	"ARRIVED AT DESTINATION STATION":                                      ShipmentStatusOnDelivery,
	"YOUR PARCEL IS IN TRANSIT TO THE REVISED ADDRESS PROVIDED BY SENDER": ShipmentStatusOnDelivery,
	"ARRIVED AT HUB STATION - INTERNATIONAL":                              ShipmentStatusOnDelivery,
	"IN TRANSIT - CROSS BORDER TRANSPORTATION":                            ShipmentStatusOnDelivery,
	"CUSTOMS CLEARANCE":                                                   ShipmentStatusOnDelivery,
	"ARRIVED AT COLLECTION STATION":                                       ShipmentStatusOnDelivery,
	"YOUR PARCEL IS IN TRANSIT":                                           ShipmentStatusOnDelivery,
	"CLOSED ON ARRIVAL":                                                   ShipmentStatusOnDelivery,
	"AWAITING CONSIGNEE COLLECTION":                                       ShipmentStatusOnDelivery,
	"CUSTOMER MOVED":                                                      ShipmentStatusOnDelivery,
	"YOUR PARCELS ARE PARTIALLY DELIVERED":                                ShipmentStatusOnDelivery,
	"YOUR PARCEL IS IN TRANSIT TO RETURN TO ORIGIN":                       ShipmentStatusOnDelivery,
	"DELIVERY UNSUCCESSFUL":                                               ShipmentStatusOnDelivery,
	"YOUR PARCEL HAS BEEN SUCCESSFULLY DELIVERED":                         ShipmentStatusDelivered,
	"YOUR PARCEL HAS BEEN RETURNED":                                       ShipmentStatusFailedDelivery,
}
