import { apiRequest } from "@/shared/api/request"; import { API_ENDPOINTS, API_OPERATIONS, apiEndpointPath } from "@/shared/api/generated/endpoints"; export { listRegions } from "@/shared/api/regions"; import type { AgencyDto, AgencyHostAddPayload, AgencyJoinEnabledPayload, AgencyStatusPayload, AdminJobDto, ApiList, ApiPage, BDLeaderPositionAliasPayload, BDProfileDto, BDStatusPayload, CoinSellerDto, CoinSellerSalaryRatesDto, CoinSellerSalaryRatesPayload, CoinSellerSubApplicationDto, CoinSellerSubApplicationReviewPayload, CoinSellerSubApplicationReviewResultDto, CoinSellerStockCreditDto, CoinSellerStockCreditPayload, CoinSellerStockDebitDto, CoinSellerStockDebitPayload, CoinSellerStatusPayload, CountryCodeRenameJobDto, CountryDto, CountryPayload, CountryRenameCodePayload, CountryUpdatePayload, CreateAgencyPayload, CreateAgencyResultDto, CreateBDLeaderPayload, CreateBDPayload, CreateCoinSellerPayload, CreateManagerPayload, EntityId, HostCommandPayload, HostWithdrawalDto, HostProfileDto, ManagerDto, PageQuery, RegionCountriesPayload, RegionDto, RegionPayload, RegionUpdatePayload, SalaryWalletAdjustPayload, SalaryWalletAdjustResultDto, SalaryWalletHistoryDto, UpdateManagerPayload, } from "@/shared/api/types"; export function listCountries(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listCountries; return apiRequest>(apiEndpointPath(API_OPERATIONS.listCountries), { method: endpoint.method, query, }); } export function getCountry(countryId: EntityId): Promise { const endpoint = API_ENDPOINTS.getCountry; return apiRequest(apiEndpointPath(API_OPERATIONS.getCountry, { country_id: countryId }), { method: endpoint.method, }); } export function createCountry(payload: CountryPayload): Promise { const endpoint = API_ENDPOINTS.createCountry; return apiRequest(apiEndpointPath(API_OPERATIONS.createCountry), { body: payload, method: endpoint.method, }); } export function updateCountry(countryId: EntityId, payload: CountryUpdatePayload): Promise { const endpoint = API_ENDPOINTS.updateCountry; return apiRequest( apiEndpointPath(API_OPERATIONS.updateCountry, { country_id: countryId }), { body: payload, method: endpoint.method, }, ); } export function renameCountryCode( countryId: EntityId, payload: CountryRenameCodePayload, ): Promise { const endpoint = API_ENDPOINTS.renameCountryCode; return apiRequest( apiEndpointPath(API_OPERATIONS.renameCountryCode, { country_id: countryId }), { body: payload, method: endpoint.method, }, ); } export function getJob(jobId: EntityId): Promise { const endpoint = API_ENDPOINTS.getJob; return apiRequest(apiEndpointPath(API_OPERATIONS.getJob, { id: jobId }), { method: endpoint.method, }); } export function enableCountry(countryId: EntityId): Promise { const endpoint = API_ENDPOINTS.enableCountry; return apiRequest(apiEndpointPath(API_OPERATIONS.enableCountry, { country_id: countryId }), { method: endpoint.method, }); } export function disableCountry(countryId: EntityId): Promise { const endpoint = API_ENDPOINTS.disableCountry; return apiRequest(apiEndpointPath(API_OPERATIONS.disableCountry, { country_id: countryId }), { method: endpoint.method, }); } export function deleteCountry(countryId: EntityId): Promise { const endpoint = API_ENDPOINTS.deleteCountry; return apiRequest(apiEndpointPath(API_OPERATIONS.deleteCountry, { country_id: countryId }), { method: endpoint.method, }); } export function getRegion(regionId: EntityId): Promise { const endpoint = API_ENDPOINTS.getRegion; return apiRequest(apiEndpointPath(API_OPERATIONS.getRegion, { region_id: regionId }), { method: endpoint.method, }); } export function createRegion(payload: RegionPayload): Promise { const endpoint = API_ENDPOINTS.createRegion; return apiRequest(apiEndpointPath(API_OPERATIONS.createRegion), { body: payload, method: endpoint.method, }); } export function updateRegion(regionId: EntityId, payload: RegionUpdatePayload): Promise { const endpoint = API_ENDPOINTS.updateRegion; return apiRequest( apiEndpointPath(API_OPERATIONS.updateRegion, { region_id: regionId }), { body: payload, method: endpoint.method, }, ); } export function replaceRegionCountries(regionId: EntityId, payload: RegionCountriesPayload): Promise { const endpoint = API_ENDPOINTS.replaceRegionCountries; return apiRequest( apiEndpointPath(API_OPERATIONS.replaceRegionCountries, { region_id: regionId }), { body: payload, method: endpoint.method, }, ); } export function enableRegion(regionId: EntityId): Promise { const endpoint = API_ENDPOINTS.enableRegion; return apiRequest(apiEndpointPath(API_OPERATIONS.enableRegion, { region_id: regionId }), { method: endpoint.method, }); } export function disableRegion(regionId: EntityId): Promise { const endpoint = API_ENDPOINTS.disableRegion; return apiRequest(apiEndpointPath(API_OPERATIONS.disableRegion, { region_id: regionId }), { method: endpoint.method, }); } export function listBDLeaders(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listBDLeaders; return apiRequest>(apiEndpointPath(API_OPERATIONS.listBDLeaders), { method: endpoint.method, query, }); } export function listBDs(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listBDs; return apiRequest>(apiEndpointPath(API_OPERATIONS.listBDs), { method: endpoint.method, query, }); } export function listAgencies(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listAgencies; return apiRequest>(apiEndpointPath(API_OPERATIONS.listAgencies), { method: endpoint.method, query, }); } export function listManagers(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listManagers; return apiRequest>(apiEndpointPath(API_OPERATIONS.listManagers), { method: endpoint.method, query, }); } export function createManager(payload: CreateManagerPayload): Promise { const endpoint = API_ENDPOINTS.createManager; return apiRequest(apiEndpointPath(API_OPERATIONS.createManager), { body: payload, method: endpoint.method, }); } export function updateManager(userId: EntityId, payload: UpdateManagerPayload): Promise { const endpoint = API_ENDPOINTS.updateManager; return apiRequest( apiEndpointPath(API_OPERATIONS.updateManager, { user_id: userId }), { body: payload, method: endpoint.method, }, ); } export function listHosts(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listHosts; return apiRequest>(apiEndpointPath(API_OPERATIONS.listHosts), { method: endpoint.method, query, }); } export function listCoinSellers(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listCoinSellers; return apiRequest>(apiEndpointPath(API_OPERATIONS.listCoinSellers), { method: endpoint.method, query, }); } export function listCoinSellerSubSellers(userId: EntityId, query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listCoinSellerSubSellers; return apiRequest>( apiEndpointPath(API_OPERATIONS.listCoinSellerSubSellers, { user_id: userId }), { method: endpoint.method, query, }, ); } export function listCoinSellerSubApplications(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listCoinSellerSubApplications; return apiRequest>( apiEndpointPath(API_OPERATIONS.listCoinSellerSubApplications), { method: endpoint.method, query, }, ); } export function listHostWithdrawals(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listHostWithdrawals; return apiRequest>(apiEndpointPath(API_OPERATIONS.listHostWithdrawals), { method: endpoint.method, query, }); } export function listSalaryWalletHistory(query: PageQuery = {}): Promise> { return apiRequest>("/v1/admin/host-org/salary-wallets/history", { method: "GET", query, }); } export function adjustSalaryWallet(payload: SalaryWalletAdjustPayload): Promise { return apiRequest( "/v1/admin/host-org/salary-wallets/adjust", { body: payload, method: "POST", }, ); } export function createBDLeader(payload: CreateBDLeaderPayload): Promise { const endpoint = API_ENDPOINTS.createBDLeader; return apiRequest(apiEndpointPath(API_OPERATIONS.createBDLeader), { body: payload, method: endpoint.method, }); } export function createBD(payload: CreateBDPayload): Promise { const endpoint = API_ENDPOINTS.createBD; return apiRequest(apiEndpointPath(API_OPERATIONS.createBD), { body: payload, method: endpoint.method, }); } export function deleteBDLeader(userId: EntityId): Promise { return apiRequest(`/v1/admin/bd-leaders/${encodeURIComponent(String(userId))}`, { method: "DELETE", }); } export function updateBDLeaderPositionAlias( userId: EntityId, payload: BDLeaderPositionAliasPayload, ): Promise { return apiRequest( `/v1/admin/bd-leaders/${encodeURIComponent(String(userId))}/position-alias`, { body: payload, method: "PATCH", }, ); } export function setBDLeaderStatus(userId: EntityId, payload: BDStatusPayload): Promise { const endpoint = API_ENDPOINTS.setBDLeaderStatus; return apiRequest( apiEndpointPath(API_OPERATIONS.setBDLeaderStatus, { user_id: userId }), { body: payload, method: endpoint.method, }, ); } export function setBDStatus(userId: EntityId, payload: BDStatusPayload): Promise { const endpoint = API_ENDPOINTS.setBDStatus; return apiRequest(apiEndpointPath(API_OPERATIONS.setBDStatus, { user_id: userId }), { body: payload, method: endpoint.method, }); } export function createCoinSeller(payload: CreateCoinSellerPayload): Promise { const endpoint = API_ENDPOINTS.createCoinSeller; return apiRequest(apiEndpointPath(API_OPERATIONS.createCoinSeller), { body: payload, method: endpoint.method, }); } export function setCoinSellerStatus(userId: EntityId, payload: CoinSellerStatusPayload): Promise { const endpoint = API_ENDPOINTS.setCoinSellerStatus; return apiRequest( apiEndpointPath(API_OPERATIONS.setCoinSellerStatus, { user_id: userId }), { body: payload, method: endpoint.method, }, ); } export function approveCoinSellerSubApplication( applicationId: EntityId, payload: CoinSellerSubApplicationReviewPayload, ): Promise { const endpoint = API_ENDPOINTS.approveCoinSellerSubApplication; return apiRequest( apiEndpointPath(API_OPERATIONS.approveCoinSellerSubApplication, { application_id: applicationId }), { body: payload, method: endpoint.method, }, ); } export function rejectCoinSellerSubApplication( applicationId: EntityId, payload: CoinSellerSubApplicationReviewPayload, ): Promise { const endpoint = API_ENDPOINTS.rejectCoinSellerSubApplication; return apiRequest( apiEndpointPath(API_OPERATIONS.rejectCoinSellerSubApplication, { application_id: applicationId }), { body: payload, method: endpoint.method, }, ); } export function creditCoinSellerStock( userId: EntityId, payload: CoinSellerStockCreditPayload, ): Promise { const endpoint = API_ENDPOINTS.creditCoinSellerStock; return apiRequest( apiEndpointPath(API_OPERATIONS.creditCoinSellerStock, { user_id: userId }), { body: payload, method: endpoint.method, }, ); } export function debitCoinSellerStock( userId: EntityId, payload: CoinSellerStockDebitPayload, ): Promise { const endpoint = API_ENDPOINTS.debitCoinSellerStock; return apiRequest( apiEndpointPath(API_OPERATIONS.debitCoinSellerStock, { user_id: userId }), { body: payload, method: endpoint.method, }, ); } export function getCoinSellerSalaryRates(regionId: EntityId): Promise { const endpoint = API_ENDPOINTS.getCoinSellerSalaryRates; return apiRequest( apiEndpointPath(API_OPERATIONS.getCoinSellerSalaryRates, { region_id: regionId }), { method: endpoint.method, }, ); } export function replaceCoinSellerSalaryRates( regionId: EntityId, payload: CoinSellerSalaryRatesPayload, ): Promise { const endpoint = API_ENDPOINTS.replaceCoinSellerSalaryRates; return apiRequest( apiEndpointPath(API_OPERATIONS.replaceCoinSellerSalaryRates, { region_id: regionId }), { body: payload, method: endpoint.method, }, ); } export function createAgency(payload: CreateAgencyPayload): Promise { const endpoint = API_ENDPOINTS.createAgency; return apiRequest(apiEndpointPath(API_OPERATIONS.createAgency), { body: payload, method: endpoint.method, }); } export function adminAddAgencyHost(agencyId: EntityId, payload: AgencyHostAddPayload): Promise { const endpoint = API_ENDPOINTS.adminAddAgencyHost; return apiRequest( apiEndpointPath(API_OPERATIONS.adminAddAgencyHost, { agency_id: agencyId }), { body: payload, method: endpoint.method, }, ); } export function closeAgency(agencyId: EntityId, payload: HostCommandPayload): Promise { const endpoint = API_ENDPOINTS.closeAgency; return apiRequest( apiEndpointPath(API_OPERATIONS.closeAgency, { agency_id: agencyId }), { body: payload, method: endpoint.method, }, ); } export function deleteAgency(agencyId: EntityId, payload: HostCommandPayload): Promise { const endpoint = API_ENDPOINTS.deleteAgency; return apiRequest( apiEndpointPath(API_OPERATIONS.deleteAgency, { agency_id: agencyId }), { body: payload, method: endpoint.method, }, ); } export function setAgencyStatus(agencyId: EntityId, payload: AgencyStatusPayload): Promise { const endpoint = API_ENDPOINTS.setAgencyStatus; return apiRequest( apiEndpointPath(API_OPERATIONS.setAgencyStatus, { agency_id: agencyId }), { body: payload, method: endpoint.method, }, ); } export function setAgencyJoinEnabled(agencyId: EntityId, payload: AgencyJoinEnabledPayload): Promise { const endpoint = API_ENDPOINTS.setAgencyJoinEnabled; return apiRequest( apiEndpointPath(API_OPERATIONS.setAgencyJoinEnabled, { agency_id: agencyId }), { body: payload, method: endpoint.method, }, ); }