import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http' export type OverseasFeeType = 'STORAGE' | 'RETURN_STORAGE' export type OverseasBillingUnit = 'CBM' | 'PALLET' export interface OverseasStorageFeeTier { id: string startDay: number endDay: number | null unitPrice: number sortNo: number feeType: OverseasFeeType billingUnit: OverseasBillingUnit } export interface OverseasStorageFeeConfig { id: string customerId: string customerName: string currency: string tiers: OverseasStorageFeeTier[] version: number createdAt: string | null updatedAt: string | null } export interface OverseasStorageFeeUpdateRequest { customerId: string customerName: string currency: string tiers: Array> version: number } const path = (tenantId: string) => `/platform/v1/iam/tenants/${encodeURIComponent(tenantId)}/overseas-storage-fees` type RawConfig = Omit & { id: string | number customerId: string | number version: string | number tiers: Array & { id: string | number; unitPrice: number | string }> } function normalize(data: RawConfig): OverseasStorageFeeConfig { return { ...data, id: String(data.id), customerId: String(data.customerId), version: Number(data.version), tiers: data.tiers.map((tier) => ({ ...tier, id: String(tier.id), endDay: tier.endDay == null ? null : Number(tier.endDay), unitPrice: Number(tier.unitPrice), feeType: tier.feeType as OverseasFeeType, billingUnit: tier.billingUnit as OverseasBillingUnit })), } } export async function getCustomerOverseasStorageFees(tenantId: string) { const response = await http.get>(path(tenantId)) return normalize(unwrapApiResponse(response)) } export async function updateCustomerOverseasStorageFees(tenantId: string, request: OverseasStorageFeeUpdateRequest) { const response = await http.put>(path(tenantId), request) unwrapApiResponse(response) return getCustomerOverseasStorageFees(tenantId) } export async function listOverseasStorageFees(page = 1, size = 20, customerName?: string) { const response = await http.get>('/platform/v1/overseas-storage-fees', { params: { page, size, customerName } }) const result = unwrapApiResponse(response) return { ...result, records: (result.records || []).map(normalize), total: Number(result.total || 0), page: Number(result.page || page), size: Number(result.size || size) } }