import { rpcOrNull, rpcOrValue } from '@/services/analytics/rpc.uts' export type AdminUserLabel = { id: string name: string color: string | null remark: string | null status: number created_at: string | null updated_at: string | null deleted_at: string | null } export type AdminUserLabelPageResult = { total: number items: Array } export type AdminUserLabelPageFilters = { search?: string | null status?: number | null includeDeleted?: boolean } export async function fetchAdminUserLabelPage( page: number, pageSize: number, filters: AdminUserLabelPageFilters = {} ): Promise { const res = await rpcOrNull('rpc_admin_user_label_list', { p_page: page, p_page_size: pageSize, p_search: filters.search ?? null, p_status: filters.status ?? null, p_include_deleted: filters.includeDeleted ?? false } as any) if (res == null) return { total: 0, items: [] as Array } const anyTotal = (res as any).total const anyItems = (res as any).items const total = typeof anyTotal === 'number' ? anyTotal : parseInt(String(anyTotal ?? '0')) const items = Array.isArray(anyItems) ? (anyItems as Array) : ([] as Array) return { total, items: items as Array } } export type SaveAdminUserLabelInput = { id?: string | null name: string color?: string | null remark?: string | null status?: number } export async function saveAdminUserLabel(input: SaveAdminUserLabelInput): Promise { const res = await rpcOrValue('rpc_admin_user_label_save', { p_id: input.id ?? null, p_name: input.name, p_color: input.color ?? null, p_remark: input.remark ?? null, p_status: input.status ?? 1 } as any) return res != null ? String(res) : null } export async function deleteAdminUserLabel(id: string): Promise { const ok = await rpcOrValue('rpc_admin_user_label_delete', { p_id: id } as any) return ok === true } export async function setAdminUserLabelStatus(id: string, status: number): Promise { const ok = await rpcOrValue('rpc_admin_user_label_set_status', { p_id: id, p_status: status } as any) return ok === true }