
import json
from ali_express_ds.iop.ali_express_sdk import IopClient, IopRequest
from mama_care_api.settings import APP_KEY, APP_SECRET, ACCESS_TOKEN

def getProduct(shipToCountry, productId, targetCurrency, targetLanguage, removePersonalBenefit):
    client = IopClient("https://api-sg.aliexpress.com/sync", APP_KEY, APP_SECRET)
    #aliexpress.ds.product.get
    #aliexpress.ds.product.wholesale.get
    request = IopRequest("aliexpress.ds.product.wholesale.get")
    request.add_api_param("ship_to_country", shipToCountry)
    request.add_api_param("product_id", productId)
    request.add_api_param("target_currency", targetCurrency)
    request.add_api_param("target_language", targetLanguage)
    request.add_api_param("remove_personal_benefit", removePersonalBenefit)
    # request.add_api_param('biz_model', 'biz_model')
    # request.add_api_param('province_code', 'provice')
    # request.add_api_param('city_code', 'city')
    response = client.execute(request, ACCESS_TOKEN)
    return response.body

def getFreight(quantity, shipToCountry, productId, selectedSkuId, language, currency, locale):
    data = {
        "quantity": quantity,
        "shipToCountry": shipToCountry,
        "productId": productId,
        "selectedSkuId": selectedSkuId,
        "language": language,
        "currency": currency,
        "locale": locale,
    }

    client = IopClient("https://api-sg.aliexpress.com/sync", APP_KEY, APP_SECRET)
    request = IopRequest("aliexpress.ds.freight.query")
    request.add_api_param("queryDeliveryReq", json.dumps(data))
    response = client.execute(request, ACCESS_TOKEN)
    return response.body