//
//  LNHttpManager+Purchase.swift
//  Lanu
//
//  Created by OneeChan on 2025/12/22.
//

import Foundation
import UIKit
import SnapKit


private let kNetPath_Purchase_Wallet = "/user/my/wallet"

private let kNetPath_Purchase_Goods = "/wallet/recharge/goods"
private let kNetPath_Purchase_Create = "/wallet/recharge/submit"
private let kNetPath_Purchase_Verify = "/wallet/recharge/goods/payBak"

private let kNetPath_Purchase_Exchange = "/wallet/exchange"
private let kNetPath_Purchase_Pre = "/wallet/exchange/pre"


extension LNHttpManager {
    func getWalletInfo(completion: @escaping (LNUserWalletInfoResponse?, LNHttpError?) -> Void) {
        post(path: kNetPath_Purchase_Wallet, completion: completion)
    }
    
    func getGoodsList(currencyType: LNCurrencyType, completion: @escaping (LNPurchaseGoodsListResponse?, LNHttpError?) -> Void) {
        post(path: kNetPath_Purchase_Goods, params: [
            "walletType": currencyType.rawValue,
            "rechargePlatform": LNPurchasePlatform.iOS.rawValue
        ], completion: completion)
    }
    
    func createPurchase(id: String, completion: @escaping (LNPurchaseCreateOrderResponse?, LNHttpError?) -> Void) {
        post(path: kNetPath_Purchase_Create, params: [
            "id": id
        ], completion: completion)
    }
    
    func exchangeCurrency(from: LNCurrencyType, to: LNCurrencyType,
                          amount: Double, completion: @escaping (LNHttpError?) -> Void) {
        post(path: kNetPath_Purchase_Exchange, params: [
            "fromWalletType": from.rawValue,
            "toWalletType": to.rawValue,
            "amount": amount
        ], completion: completion)
    }
    
    func verifyPurchase(orderId: String, receipt: String, completion: @escaping (LNHttpError?) -> Void) {
        post(path: kNetPath_Purchase_Verify, params: [
            "userId": myUid,
            "orderId": orderId,
            "payType": LNPurchasePayType.apple.rawValue,
            "receipt": receipt
        ], completion: completion)
    }
    
    func getExchangeExpectResult(from: LNCurrencyType, to: LNCurrencyType, count: Double,
                                 completion: @escaping (LNExchangeExpectResponse?, LNHttpError?) -> Void) {
        post(path: kNetPath_Purchase_Pre, params: [
            "fromWalletType": from.rawValue,
            "toWalletType": to.rawValue,
            "amount": count
        ], completion: completion)
    }
}
