//
//  CfLogECom.swift
//  ReactNativeCfEcom
//
//  Created by MOIZ HASSAN KHAN on 15/12/23.
//  Copyright © 2023 Facebook. All rights reserved.
//

import Foundation
import CausalFoundrySDKEcom

@objc(CfLogECom)
class CfLogECom: NSObject {

   @objc
    func logItemEvent(_ viewAction: String, itemString: String, catalogObject: String?, updateImmediately: Bool) {

        let cfItemEvent = CfLogItemEvent()
            .setItemAction(itemActionValue: viewAction)
            .setItem(itemJsonString: itemString)
            .updateImmediately(updateImmediately: updateImmediately)

        if(catalogObject != nil){
            cfItemEvent.setCatalogProperties(catalogPropertiesString: catalogObject!)
        }
        cfItemEvent.build()
   }
    
    @objc
     func logCartEvent(_ cartId: String, cartAction: String, itemString: String, cartPrice: NSNumber, currency: String, updateImmediately: Bool) {
         let cartPricefloatValue = cartPrice.floatValue
         CfLogCartEvent()
             .setCartId(cartId: cartId)
             .setCartAction(cartAction: cartAction)
             .setItem(itemJsonString: itemString)
             .setCurrency(currencyCode: currency)
             .setCartPrice(cartPrice: cartPricefloatValue)
             .updateImmediately(updateImmediately: updateImmediately)
             .build()
    }
    
    
    @objc
     func logCheckoutEvent(_ orderId: String, cartId: String, isSuccessful: Bool, cartPrice: NSNumber, currency: String, shopMode: String?, itemListString: String, updateImmediately: Bool) {
         let cartPricefloatValue = cartPrice.floatValue
         
         CfLogCheckoutEvent()
             .setOrderId(orderId: orderId)
             .setCartId(cartId: cartId)
             .isSuccessful(isSuccessfulValue: isSuccessful)
             .setPrice(priceValue: cartPricefloatValue)
             .setCurrency(currencyValue: currency)
             .setShopMode(shopMode: (shopMode != nil) ? shopMode! : "delivery")
             .addItemList(itemListString: itemListString)
             .updateImmediately(updateImmediately: updateImmediately)
             .build()
    }
    
    
    @objc
    func logDeliveryEvent(_ orderId: String, action: String, deliveryId: String, isUrgent: Bool, dateTimeMillis: Double, deliveryCoordinates: String?, dispatchCoordinates: String?, updateImmediately: Bool) {
         
         CfLogDeliveryEvent()
             .setOrderId(orderId: orderId)
             .setDeliveryAction(action: action)
             .setDeliveryId(deliveryId: deliveryId)
             .setDeliveryDateTime(deliveryTs: Int64(dateTimeMillis))
             .setDeliveryCoordinates(deliveryCoordinatesJsonString: deliveryCoordinates)
             .setDispatchCoordinates(dispatchCoordinatesJsonString: dispatchCoordinates)
             .isUrgent(isUrgent: isUrgent)
             .build()
    }
    
    
    @objc
     func logCancelCheckoutEvent(_ checkoutId: String, cancelType: String, itemTypeArrayJson: String, reason: String, updateImmediately: Bool) {
         
         CfLogCancelCheckoutEvent()
             .setCheckoutId(checkoutId: checkoutId)
             .setCancelType(cancelTypeString: cancelType)
             .addItemList(itemListString: itemTypeArrayJson)
             .setCancelReason(reason: reason)
             .updateImmediately(updateImmediately: updateImmediately)
             .build()
    }
    
    
    @objc
     func logItemReportEvent(_ itemObject: String, storeObject: String, reportObject: String, updateImmediately: Bool) {
         
         CfLogItemReportEvent()
             .setItem(itemJsonString: itemObject)
             .setStoreObject(storeObjectString: storeObject)
             .setReportObject(reportObjectString: reportObject)
             .updateImmediately(updateImmediately: updateImmediately)
             .build()
    }
    
    
    @objc
     func logItemRequestEvent(_ requestId: String, itemName: String, manufacturer: String, updateImmediately: Bool) {
         
         CfLogItemRequestEvent()
             .setItemRequestId(itemRequestId: requestId)
             .setItemName(itemName: itemName)
             .setItemManufacturer(manufacturer: manufacturer)
             .updateImmediately(updateImmediately: updateImmediately)
             .build()
    }
    
    
    @objc
     func logItemVerificationEvent(_ scanChannel: String, scanType: String, isSuccessful: Bool, itemInfo: String?, updateImmediately: Bool) {
         
         let itemVerificationObject = CfLogItemVerificationEvent()
             .setScanChannel(scanChannel: scanChannel)
             .setScanType(scanType: scanType)
             .isSuccessful(isSuccessful: isSuccessful)
         
         if(itemInfo != nil){
             itemVerificationObject.setItemInfo(itemInfoObjectString: itemInfo!)
         }
             
         itemVerificationObject.updateImmediately(updateImmediately: updateImmediately)
         itemVerificationObject.build()
    }
    
    
    @objc
     func logItemImpressionEvent(_ recyclerId: String, visibleItems: String) {
         
         if(!visibleItems.isEmpty){
             CfItemImpressionListener()
                 .setImpressionProperties(itemImpressionModelString: visibleItems)
                 .build()
         }
    }
    
    
    @objc
     func updateDrugCatalog(_ itemId: String, drugCatalogModel: String) {
         
         CfEComCatalog.updateDrugCatalog(drugId: itemId, drugCatalogModel: drugCatalogModel)
    }
    
    
    @objc
     func updateGroceryCatalog(_ itemId: String, groceryItemModel: String) {
         
         CfEComCatalog.updateGroceryCatalog(itemId: itemId, groceryCatalogModel: groceryItemModel)
    }
    
    
    @objc
     func updateBloodCatalog(_ itemId: String, bloodCatalogModel: String) {
         
         CfEComCatalog.updateBloodCatalog(itemId: itemId, bloodCatalogModel: bloodCatalogModel)
    }
    
    
    @objc
     func updateOxygenCatalog(_ itemId: String, oxygenCatalogModel: String) {
         
         CfEComCatalog.updateOxygenCatalog(itemId: itemId, oxygenCatalogModel: oxygenCatalogModel)
    }
    
    
    @objc
     func updateMedicalEquipmentCatalog(_ itemId: String, medicalEquipmentCatalogModel: String) {
         
         CfEComCatalog.updateMedicalEquipmentCatalog(itemId: itemId, medicalEquipmentCatalogModel: medicalEquipmentCatalogModel)
    }
    
    
    @objc
     func updateFacilityCatalog(_ itemId: String, facilityCatalogModel: String) {
         
         CfEComCatalog.updateFacilityCatalog(facilityId: itemId, facilityCatalogModel: facilityCatalogModel)
    }
    

    @objc
      static func requiresMainQueueSetup() -> Bool {
        return true
      }

//  @objc(multiply:withB:withResolver:withRejecter:)
//  func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
//    resolve(a*b)
//  }
}




