import { CurrencyCode } from "../../core/commonTypes";
import { GenericMeta } from "../../core/commonTypes";

export type ISO8601Format = string;

export enum ECommerceTypes {
  CancelCheckout = "cancel_checkout",
  Cart = "cart",
  Checkout = "checkout",
  Delivery = "delivery",
  Item = "item",
  ItemReport = "item_report",
  ItemRequest = "item_request",
  ItemVerification = "item_verification",
}

export enum ECommerceCatalogType {
  Drug = "drug",
  Grocery = "grocery",
  Blood = "blood",
  Oxygen = "oxygen",
  MedicalEquipment = "medical_equipment",
  Facility = "facility",
}

export enum ItemAction {
  View = "view",
  Detail = "detail",
  Impression = "impression",
  TopUp = "top_up",
  Cancel = "cancel",
  Update = "update",
  Remove = "remove",
  Add = "add",
  Select = "select",
  AddFavorite = "add_favorite",
  RemoveFavorite = "remove_favorite",
  AddReminder = "add_reminder",
  RemoveReminder = "remove_reminder",
  RemoveReminderAuto = "remove_reminder_auto",
  Other = "other",
}

export enum ItemType {
  Blood = "blood",
  Book = "book",
  Clothing = "clothing",
  Drug = "drug",
  Grocery = "grocery",
  Subscription = "subscription",
  Facility = "facility",
  Electronics = "electronics",
  MedicalEquipment = "medical_equipment",
  Misc = "misc",
  Oxygen = "oxygen",
  ItemVerification = "item_verification",
  ItemReport = "item_report",
  Reward = "reward",
  Survey = "survey",
  Other = "other",
}

export enum ScanChannel {
  App = "app",
  Ussd = "ussd",
}

export enum ScanType {
  Pin = "pin",
  QrCode = "qr_code",
}

export enum StockStatus {
  InStock = "in_stock",
  LowStock = "low_stock",
  OutOfStock = "out_of_stock",
}

export type ItemObject = {
  id: string;
  type: ItemType;
  quantity: number;
  price: number;
  currency: CurrencyCode;
  stock_status?: StockStatus;
  promo_id?: string;
  facility_id?: string;
  discount?: number;
};

export interface ItemProperties {
  action: ItemAction;
  item: ItemObject;
  meta?: GenericMeta;
}

export interface StoreObject {
  id: string;
  lat?: number;
  lon?: number;
}

export enum CartAction {
  AddItem = "add_item",
  RemoveItem = "remove_item",
}
export interface CartProperties {
  cart_id: string;
  action: CartAction;
  item: ItemObject;
  meta?: GenericMeta;
}

export enum ListAction {
  Add = "add_item",
  Discard = "discard",
  Edit = "edit_item",
  Remove = "remove_item",
  View = "view",
  Expired = "expired",
}

export enum ListType {
  Cart = "cart",
  Favourite = "favourite",
  Order = "order",
  Reminder = "reminder",
}

export enum ShopMode {
  Delivery = "delivery",
  Pickup = "pickup",
}

export interface CheckoutProperties {
  order_id: string;
  is_successful: boolean;
  cart_price: number;
  items: ItemObject[];
  cart_id: string;
  shop_mode?: ShopMode;
  meta?: any;
}

export interface CheckoutInternalProperties {
  order_id: string;
  is_successful: boolean;
  cart_price: number;
  items: any;
  cart_id: string;
  shop_mode?: ShopMode;
  meta?: any;
}

export enum DeliveryAction {
  Schedule = "schedule",
  Update = "update",
  Dispatch = "dispatch",
  Delivered = "delivered",
}

export interface DeliveryProperties {
  delivery_id: string;
  order_id: string;
  is_urgent: boolean; // true = emergency, false = schedule
  action: DeliveryAction;
  est_delivery_ts?: string;
  delivery_coordinates?: number[];
  dispatch_coordinates?: number[];
  meta?: GenericMeta;
}

export interface DrugCatalog {
  market_id: string;
  name: string;
  description?: string;
  supplier_id: string;
  supplier_name: string;
  producer?: string;
  packaging?: string;
  active_ingredients: string[];
  drug_form?: string;
  drug_strength?: string;
  atc_anatomical_group?: string;
  otc_or_ethical?: string;
  meta?: GenericMeta;
}

export interface GroceryCatalog {
  name: string;
  description?: string;
  category?: string;
  active_ingredients?: string[];
  market_id?: string;
  packaging?: string;
  packaging_size?: number;
  packaging_units?: string;
  producer?: string;
  supplier_id?: string;
  supplier_name?: string;
  meta?: GenericMeta;
}

export interface FacilityCatalog {
  name: string;
  type?: string;
  country?: string;
  region_state?: string;
  city?: string;
  is_active?: boolean;
  has_delivery?: boolean;
  is_sponsored?: boolean;
  meta?: GenericMeta;
}

export enum CancelType {
  Cart = "cart",
  Order = "order",
}

export interface CancelCheckoutProperties {
  cancel_type_id: string;
  type: CancelType;
  items: string[];
  reason: string;
  meta?: GenericMeta;
}

export interface ItemReportProperties {
  item_id: string;
  item_type: ItemType;
  report_id: string;
  report_remarks: string;
  store_id: string;
  meta?: GenericMeta;
}

export interface ItemRequestProperties {
  item_id: string;
  item_name: string;
  manufacturer: string;
}

export interface ItemInfoObject {
  id: string;
  type: ItemType;
  batch_id?: string;
  reward_id?: string;
  survey_id?: string;
  is_featured?: boolean;
  expiry_date?: number;
  production_date?: number;
}

export interface ItemVerificationProperties {
  scan_channel: ScanChannel;
  scan_type: ScanType;
  is_successful: boolean;
  item_info: ItemInfoObject;
}
