import { apiClient } from '@/shared/api/client'

export async function fetchUnreadMessageCount(): Promise<{ count: number }> {
  const { data } = await apiClient.get<{ count: number }>('me/messages/unread-count')
  return data
}

export async function markOrderMessagesRead(orderId: string): Promise<void> {
  await apiClient.post(`me/orders/${orderId}/messages/read`)
}

export type ConversationSummary = {
  orderId: string
  status: string
  deliveryType: 'delivery' | 'pickup'
  lastMessageAt: string
  preview: string
  unreadCount: number
}

export async function fetchMyConversations(): Promise<{ items: ConversationSummary[] }> {
  const { data } = await apiClient.get<{ items: ConversationSummary[] }>('me/conversations')
  return data
}
