//
//  CanRepository.swift
//  SodaLive
//
//  Created by klaus on 2023/08/10.
//

import Foundation
import CombineMoya
import Combine
import Moya

final class CanRepository {
    private let api = MoyaProvider<CanApi>()
    
    func getCanStatus() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getCanStatus)
    }
    
    func getCanChargeStatus() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getCanChargeStatus)
    }
    
    func getCanUseStatus() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getCanUseStatus)
    }
    
    func chargeCan(title: String, chargeCan: Int, price: Double, locale: String, paymentGateway: PaymentGateway = .APPLE_IAP) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.chargeCan(request: CanChargeRequest(title: title, chargeCan: chargeCan, paymentGateway: paymentGateway, price: price, locale: locale)))
    }
    
    func verify(receiptString: String, chargeId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.verify(request: CanVerifyRequest(receiptString: receiptString, chargeId: chargeId)))
    }
    
    func pgChargeCan(canId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.pgChargeCan(request: PgChargeRequest(canId: canId, paymentGateway: .PG)))
    }
    
    func pgVerify(receiptId: String, orderId: String) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.pgVerify(request: PgVerifyRequest(receiptId: receiptId, orderId: orderId)))
    }
    
    func pgVerifyHecto(receiptId: String, orderId: String) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.pgVerifyHecto(request: PgVerifyRequest(receiptId: receiptId, orderId: orderId)))
    }
    
    func getCans() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getCans)
    }
    
    func useCanCoupon(couponNumber: String) -> AnyPublisher<Response, MoyaError> {
        let request = UseCanCouponRequest(couponNumber: couponNumber)
        return api.requestPublisher(.useCanCoupon(request: request))
    }
}

