import { apiRequest } from "@/shared/api/request"; import { API_ENDPOINTS, API_OPERATIONS, apiEndpointPath } from "@/shared/api/generated/endpoints"; import type { ApiPage, CoinLedgerUserDto, EntityId, PageQuery } from "@/shared/api/types"; export interface ResourceDto { appCode?: string; resourceId: number; resourceCode?: string; resourceType?: string; name?: string; status?: string; grantable?: boolean; managerGrantEnabled?: boolean; grantStrategy?: string; walletAssetType?: string; walletAssetAmount?: number; priceType?: string; coinPrice?: number; badgeForm?: string; badgeKind?: string; levelTrack?: string; usageScopes?: string[]; assetUrl?: string; previewUrl?: string; animationUrl?: string; metadataJson?: string; sortOrder?: number; createdAtMs?: number; updatedAtMs?: number; } export interface ResourcePayload { amount: number; animationUrl?: string; assetUrl: string; badgeForm?: string; badgeKind?: string; coinPrice: number; levelTrack?: string; managerGrantEnabled: boolean; metadataJson?: string; name: string; previewUrl: string; priceType: string; resourceCode: string; resourceType: string; sortOrder: number; status: string; } export interface ResourceMp4LayoutUpdatePayload { metadataJson: string; resourceId: EntityId; } export interface ResourceMp4LayoutsPayload { items: ResourceMp4LayoutUpdatePayload[]; } export interface EmojiPackDto { appCode?: string; resourceId: number; resourceCode?: string; name?: string; status?: string; category?: string; pricingType?: string; coverUrl?: string; animationUrl?: string; regionIds?: number[]; sortOrder?: number; createdAtMs?: number; updatedAtMs?: number; } export interface EmojiPackPayload { animationUrl: string; category: string; coverUrl: string; name: string; pricingType: string; regionIds: number[]; sortOrder: number; } export interface ResourceGroupItemDto { groupItemId: number; itemType?: string; resourceId: number; resource?: ResourceDto; walletAssetType?: string; walletAssetAmount?: number; quantity?: number; durationMs?: number; sortOrder?: number; } export interface ResourceGroupDto { appCode?: string; groupId: number; groupCode?: string; name?: string; status?: string; description?: string; sortOrder?: number; items?: ResourceGroupItemDto[]; createdAtMs?: number; updatedAtMs?: number; } export interface ResourceShopItemDto { appCode?: string; shopItemId: number; resourceId: number; resource?: ResourceDto; status?: string; durationDays?: number; priceType?: string; coinPrice?: number; effectiveFromMs?: number; effectiveToMs?: number; sortOrder?: number; createdAtMs?: number; updatedAtMs?: number; } export interface ResourceShopPurchaseOrderDto { appCode?: string; orderId: string; commandId?: string; userId?: string; user?: ResourceGrantUserDto; shopItemId?: number; resourceId: number; resource?: ResourceDto; durationDays?: number; priceCoin?: number; status?: string; walletTransactionId?: string; resourceGrantId?: string; entitlementId?: string; createdAtMs?: number; updatedAtMs?: number; } export interface GiftDto { appCode?: string; giftId: string; resourceId: number; resource?: ResourceDto; status?: string; name?: string; sortOrder?: number; presentationJson?: string; priceVersion?: string; giftTypeCode?: string; cpRelationType?: string; chargeAssetType?: string; coinPrice?: number; effectiveFromMs?: number; effectiveToMs?: number; effectTypes?: string[]; createdAtMs?: number; updatedAtMs?: number; regionIds?: number[]; } export interface GiftTypeDto { appCode?: string; tabKey?: string; displayName?: string; tabName?: string; status?: string; sortOrder?: number; createdByUserId?: number; updatedByUserId?: number; createdAtMs?: number; updatedAtMs?: number; } export interface GiftPayload { giftId: string; resourceId: number; status: string; name: string; sortOrder: number; presentationJson: string; priceVersion: string; giftTypeCode: string; cpRelationType: string; chargeAssetType: string; coinPrice: number; effectiveAtMs: number; effectiveFromMs: number; effectiveToMs: number; effectTypes: string[]; regionIds: number[]; } export interface GiftTypePayload { displayName: string; tabName: string; status: string; sortOrder: number; } export interface GiftTypesPayload { items: Array; } export interface ResourceGrantItemDto { createdAtMs?: number; durationMs?: number; entitlementId?: string; grantId?: string; grantItemId?: number; quantity?: number; resourceId?: number; resourceSnapshotJson?: string; resultType?: string; walletTransactionId?: string; } export interface ResourceGrantOperatorDto { avatar?: string; displayUserId?: string; prettyDisplayUserId?: string; prettyId?: string; name?: string; source?: string; userId?: string; username?: string; } export interface ResourceGrantUserDto { avatar?: string; displayUserId?: string; prettyDisplayUserId?: string; prettyId?: string; userId?: string; username?: string; } export interface ResourceGrantDto { appCode?: string; commandId?: string; createdAtMs?: number; grantId: string; grantSource?: string; grantSubjectId?: string; grantSubjectType?: string; operator?: ResourceGrantOperatorDto; items?: ResourceGrantItemDto[]; operatorUserId?: number; reason?: string; status?: string; targetUser?: ResourceGrantUserDto; targetUserId?: string; updatedAtMs?: number; } export interface GrantResourcePayload { commandId: string; durationMs: number; quantity: number; reason: string; resourceId: number; targetUserId: string; } export interface GrantResourceGroupPayload { commandId: string; groupId: number; reason: string; targetUserId: string; } export interface ResourceGroupItemPayload { itemType: string; amount?: number; assetType?: string; durationDays?: number; resourceId?: number; sortOrder: number; } export interface ResourceGroupPayload { groupCode: string; name: string; status: string; description: string; sortOrder: number; items: ResourceGroupItemPayload[]; } export interface ResourceShopItemPayload { durationDays: number; effectiveFromMs: number; effectiveToMs: number; resourceId: number; shopItemId?: number; sortOrder: number; status: string; } export interface ResourceShopItemsPayload { items: ResourceShopItemPayload[]; } export function listResources(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listResources; return apiRequest>(apiEndpointPath(API_OPERATIONS.listResources), { method: endpoint.method, query, }); } export function createResource(payload: ResourcePayload): Promise { const endpoint = API_ENDPOINTS.createResource; return apiRequest(apiEndpointPath(API_OPERATIONS.createResource), { body: payload, method: endpoint.method, }); } export function updateResource(resourceId: EntityId, payload: ResourcePayload): Promise { const endpoint = API_ENDPOINTS.updateResource; return apiRequest( apiEndpointPath(API_OPERATIONS.updateResource, { resource_id: resourceId }), { body: payload, method: endpoint.method, }, ); } export function updateResourceMp4Layouts(items: ResourceMp4LayoutUpdatePayload[]): Promise { return apiRequest("/v1/admin/resources/mp4-layouts/batch", { body: { items }, method: "PUT", }); } export function enableResource(resourceId: EntityId): Promise { const endpoint = API_ENDPOINTS.enableResource; return apiRequest(apiEndpointPath(API_OPERATIONS.enableResource, { resource_id: resourceId }), { method: endpoint.method, }); } export function disableResource(resourceId: EntityId): Promise { const endpoint = API_ENDPOINTS.disableResource; return apiRequest(apiEndpointPath(API_OPERATIONS.disableResource, { resource_id: resourceId }), { method: endpoint.method, }); } export function listResourceGroups(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listResourceGroups; return apiRequest>(apiEndpointPath(API_OPERATIONS.listResourceGroups), { method: endpoint.method, query, }); } export function listResourceShopItems(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listResourceShopItems; return apiRequest>(apiEndpointPath(API_OPERATIONS.listResourceShopItems), { method: endpoint.method, query, }); } export function listResourceShopPurchaseOrders(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listResourceShopPurchaseOrders; return apiRequest>( apiEndpointPath(API_OPERATIONS.listResourceShopPurchaseOrders), { method: endpoint.method, query, }, ); } export function upsertResourceShopItems(payload: ResourceShopItemsPayload): Promise { const endpoint = API_ENDPOINTS.upsertResourceShopItems; return apiRequest( apiEndpointPath(API_OPERATIONS.upsertResourceShopItems), { body: payload, method: endpoint.method, }, ); } export function enableResourceShopItem(shopItemId: EntityId): Promise { const endpoint = API_ENDPOINTS.enableResourceShopItem; return apiRequest( apiEndpointPath(API_OPERATIONS.enableResourceShopItem, { shop_item_id: shopItemId }), { method: endpoint.method, }, ); } export function disableResourceShopItem(shopItemId: EntityId): Promise { const endpoint = API_ENDPOINTS.disableResourceShopItem; return apiRequest( apiEndpointPath(API_OPERATIONS.disableResourceShopItem, { shop_item_id: shopItemId }), { method: endpoint.method, }, ); } export function createResourceGroup(payload: ResourceGroupPayload): Promise { const endpoint = API_ENDPOINTS.createResourceGroup; return apiRequest(apiEndpointPath(API_OPERATIONS.createResourceGroup), { body: payload, method: endpoint.method, }); } export function updateResourceGroup(groupId: EntityId, payload: ResourceGroupPayload): Promise { const endpoint = API_ENDPOINTS.updateResourceGroup; return apiRequest( apiEndpointPath(API_OPERATIONS.updateResourceGroup, { group_id: groupId }), { body: payload, method: endpoint.method, }, ); } export function enableResourceGroup(groupId: EntityId): Promise { const endpoint = API_ENDPOINTS.enableResourceGroup; return apiRequest(apiEndpointPath(API_OPERATIONS.enableResourceGroup, { group_id: groupId }), { method: endpoint.method, }); } export function disableResourceGroup(groupId: EntityId): Promise { const endpoint = API_ENDPOINTS.disableResourceGroup; return apiRequest(apiEndpointPath(API_OPERATIONS.disableResourceGroup, { group_id: groupId }), { method: endpoint.method, }); } export function listGifts(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listGifts; return apiRequest>(apiEndpointPath(API_OPERATIONS.listGifts), { method: endpoint.method, query, }); } export function listGiftTypes(): Promise { const endpoint = API_ENDPOINTS.listGiftTypes; return apiRequest(apiEndpointPath(API_OPERATIONS.listGiftTypes), { method: endpoint.method, }); } export function updateGiftType(tabKey: string, payload: GiftTypePayload): Promise { const endpoint = API_ENDPOINTS.updateGiftType; return apiRequest( apiEndpointPath(API_OPERATIONS.updateGiftType, { type_code: tabKey }), { body: payload, method: endpoint.method, }, ); } export function updateGiftTypes(payload: GiftTypesPayload): Promise { const endpoint = API_ENDPOINTS.updateGiftTypes; return apiRequest(apiEndpointPath(API_OPERATIONS.updateGiftTypes), { body: payload, method: endpoint.method, }); } export function createGift(payload: GiftPayload): Promise { const endpoint = API_ENDPOINTS.createGift; return apiRequest(apiEndpointPath(API_OPERATIONS.createGift), { body: payload, method: endpoint.method, }); } export function updateGift(giftId: string, payload: GiftPayload): Promise { const endpoint = API_ENDPOINTS.updateGift; return apiRequest(apiEndpointPath(API_OPERATIONS.updateGift, { gift_id: giftId }), { body: payload, method: endpoint.method, }); } export function deleteGift(giftId: string): Promise { const endpoint = API_ENDPOINTS.deleteGift; return apiRequest(apiEndpointPath(API_OPERATIONS.deleteGift, { gift_id: giftId }), { method: endpoint.method, }); } export function enableGift(giftId: string): Promise { const endpoint = API_ENDPOINTS.enableGift; return apiRequest(apiEndpointPath(API_OPERATIONS.enableGift, { gift_id: giftId }), { method: endpoint.method, }); } export function disableGift(giftId: string): Promise { const endpoint = API_ENDPOINTS.disableGift; return apiRequest(apiEndpointPath(API_OPERATIONS.disableGift, { gift_id: giftId }), { method: endpoint.method, }); } export function listEmojiPacks(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listEmojiPacks; return apiRequest>(apiEndpointPath(API_OPERATIONS.listEmojiPacks), { method: endpoint.method, query, }); } export function listEmojiPackCategories(): Promise { const endpoint = API_ENDPOINTS.listEmojiPackCategories; return apiRequest(apiEndpointPath(API_OPERATIONS.listEmojiPackCategories), { method: endpoint.method, }); } export function createEmojiPack(payload: EmojiPackPayload): Promise { const endpoint = API_ENDPOINTS.createEmojiPack; return apiRequest(apiEndpointPath(API_OPERATIONS.createEmojiPack), { body: payload, method: endpoint.method, }); } export function listResourceGrants(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listResourceGrants; return apiRequest>(apiEndpointPath(API_OPERATIONS.listResourceGrants), { method: endpoint.method, query, }); } export function lookupResourceGrantTarget(userIdOrDisplayId: string | number): Promise { const endpoint = API_ENDPOINTS.lookupResourceGrantTarget; return apiRequest(apiEndpointPath(API_OPERATIONS.lookupResourceGrantTarget), { method: endpoint.method, query: { user_id: String(userIdOrDisplayId).trim() }, }); } export function grantResource(payload: GrantResourcePayload): Promise { const endpoint = API_ENDPOINTS.grantResource; return apiRequest(apiEndpointPath(API_OPERATIONS.grantResource), { body: payload, method: endpoint.method, }); } export function grantResourceGroup(payload: GrantResourceGroupPayload): Promise { const endpoint = API_ENDPOINTS.grantResourceGroup; return apiRequest(apiEndpointPath(API_OPERATIONS.grantResourceGroup), { body: payload, method: endpoint.method, }); }