import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http' import type { SupplierCategory } from '@/modules/suppliers' export type FeeItemTradeScope = 'DOMESTIC' | 'INTERNATIONAL' export type FeeItemStatus = 'ACTIVE' | 'DISABLED' export interface PlatformFeeItemResource { id: number | string category: string tradeScope: FeeItemTradeScope feeCode: string | null supplierCategory: SupplierCategory | null feeTypeName: string pickupPayable: boolean pickupReceivable: boolean warehousePayable: boolean warehouseReceivable: boolean allocationFee: boolean description: string | null status: FeeItemStatus createdByName?: string | null updatedByName?: string | null createdAt?: string | null updatedAt?: string | null } export interface SavePlatformFeeItemRequest { category: string tradeScope: FeeItemTradeScope feeTypeName: string supplierCategory: SupplierCategory | null pickupPayable: boolean pickupReceivable: boolean warehousePayable: boolean warehouseReceivable: boolean allocationFee: boolean description: string | null } export interface PlatformFeeItemQuery { category?: string tradeScope?: FeeItemTradeScope | '' keyword?: string status?: FeeItemStatus | '' page: number size: number } export interface PlatformFeeItemPage { records: PlatformFeeItemResource[] page: number size: number total: number pages: number } const basePath = '/platform/v1/fee-items' export async function listPlatformFeeItems(query: PlatformFeeItemQuery) { const response = await http.get, ApiEnvelope>(basePath, { params: { category: query.category?.trim() || undefined, tradeScope: query.tradeScope || undefined, keyword: query.keyword?.trim() || undefined, status: query.status || undefined, page: query.page, size: query.size, }, }) const result = unwrapApiResponse(response) return { ...result, records: result.records || [], page: Number(result.page), size: Number(result.size), total: Number(result.total), pages: Number(result.pages), } } export async function getPlatformFeeItem(id: number | string) { const response = await http.get, ApiEnvelope>( `${basePath}/${id}`, ) return unwrapApiResponse(response) } export async function createPlatformFeeItem(payload: SavePlatformFeeItemRequest) { const response = await http.post, ApiEnvelope>( basePath, payload, ) return unwrapApiResponse(response) } export async function updatePlatformFeeItem(id: number | string, payload: SavePlatformFeeItemRequest) { const response = await http.put, ApiEnvelope>( `${basePath}/${id}`, payload, ) return unwrapApiResponse(response) } export async function changePlatformFeeItemStatus(id: number | string, status: FeeItemStatus) { const response = await http.patch, ApiEnvelope>( `${basePath}/${id}/status`, { status }, ) return unwrapApiResponse(response) } export async function deletePlatformFeeItem(id: number | string) { const response = await http.delete, ApiEnvelope>( `${basePath}/${id}`, ) return unwrapApiResponse(response) }