/** Typed API functions for the Kontakte (Contact) resource. (FEAT-2) */
import { api, resources } from './client'
import { toQueryString, type GridifyQuery } from './gridify'
import type { Contact, Paged } from './types'

/** Payload for POST /contacts. */
export interface CreateContact {
  name: string
  email?: string | null
  phone?: string | null
  address?: string | null
  notes?: string | null
}

/** Payload for PUT /contacts/{id}. */
export type UpdateContact = Partial<CreateContact>

export function listContactsPaged(query: GridifyQuery): Promise<Paged<Contact>> {
  return api.get<Paged<Contact>>(`${resources.contacts}${toQueryString(query)}`)
}

export function getContact(id: string): Promise<Contact> {
  return api.get<Contact>(`${resources.contacts}/${id}`)
}

export function createContact(body: CreateContact): Promise<Contact> {
  return api.post<Contact>(resources.contacts, body)
}

export function updateContact(id: string, body: UpdateContact): Promise<Contact> {
  return api.put<Contact>(`${resources.contacts}/${id}`, body)
}

export function deleteContact(id: string): Promise<void> {
  return api.delete(`${resources.contacts}/${id}`)
}
