import { apiRequest } from "@/shared/api/request"; import { API_ENDPOINTS, API_OPERATIONS, apiEndpointPath } from "@/shared/api/generated/endpoints"; import type { ApiPage, ApiList, EntityId, PageQuery, RechargeBillDto, RechargeProductDto, RechargeProductPayload, ThirdPartyPaymentChannelDto, ThirdPartyPaymentMethodDto, ThirdPartyPaymentRateSyncDto, } from "@/shared/api/types"; export function listRechargeBills(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listRechargeBills; return apiRequest>(apiEndpointPath(API_OPERATIONS.listRechargeBills), { method: endpoint.method, query, }); } export function listRechargeProducts(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listRechargeProducts; return apiRequest>(apiEndpointPath(API_OPERATIONS.listRechargeProducts), { method: endpoint.method, query, }); } export function createRechargeProduct(payload: RechargeProductPayload): Promise { const endpoint = API_ENDPOINTS.createRechargeProduct; return apiRequest( apiEndpointPath(API_OPERATIONS.createRechargeProduct), { body: payload, method: endpoint.method, }, ); } export function updateRechargeProduct( productId: EntityId, payload: RechargeProductPayload, ): Promise { const endpoint = API_ENDPOINTS.updateRechargeProduct; return apiRequest( apiEndpointPath(API_OPERATIONS.updateRechargeProduct, { product_id: productId }), { body: payload, method: endpoint.method, }, ); } export function deleteRechargeProduct(productId: EntityId): Promise { const endpoint = API_ENDPOINTS.deleteRechargeProduct; return apiRequest(apiEndpointPath(API_OPERATIONS.deleteRechargeProduct, { product_id: productId }), { method: endpoint.method, }); } export function listThirdPartyPaymentChannels(): Promise> { const endpoint = API_ENDPOINTS.listThirdPartyPaymentChannels; return apiRequest>( apiEndpointPath(API_OPERATIONS.listThirdPartyPaymentChannels), { method: endpoint.method, }, ); } export function setThirdPartyPaymentMethodStatus( methodId: EntityId, payload: { enabled: boolean }, ): Promise { const endpoint = API_ENDPOINTS.setThirdPartyPaymentMethodStatus; return apiRequest( apiEndpointPath(API_OPERATIONS.setThirdPartyPaymentMethodStatus, { method_id: methodId }), { body: payload, method: endpoint.method, }, ); } export function updateThirdPartyPaymentRate( methodId: EntityId, payload: { usdToCurrencyRate: string }, ): Promise { const endpoint = API_ENDPOINTS.updateThirdPartyPaymentRate; return apiRequest( apiEndpointPath(API_OPERATIONS.updateThirdPartyPaymentRate, { method_id: methodId }), { body: payload, method: endpoint.method, }, ); } export function syncThirdPartyPaymentRates(): Promise { const endpoint = API_ENDPOINTS.syncThirdPartyPaymentRates; return apiRequest(apiEndpointPath(API_OPERATIONS.syncThirdPartyPaymentRates), { method: endpoint.method, }); }