import { api } from "@/lib/api"
import type { CreateOfferPayload, OffersResponse, Offer, ClientOffersResponse } from "@/types/offers"

export const createOffer = ["offers", "create"]
export const getOffers = ["offers", "list"]
export const getOfferById = (id: string) => ["offers", "detail", id]
export const getClientOffers = (clientId: string) => ["offers", "client", clientId]

export async function createNewOffer(payload: CreateOfferPayload) {
  const { data } = await api.post("/offers", payload)
  return data
}

export async function fetchOffers(): Promise<OffersResponse> {
  const { data } = await api.get("/offers")
  return data
}

export async function fetchOfferById(id: string): Promise<Offer> {
  const { data } = await api.get(`/offers/${id}`)
  return data
}

export async function fetchOffersByClientId(clientId: string): Promise<ClientOffersResponse> {
  const { data } = await api.get(`/offers/offer/${clientId}`)
  return data
}

export async function updateOffer(id: string, payload: Partial<CreateOfferPayload>) {
  const { data } = await api.patch(`/offers/${id}`, payload)
  return data
}

export async function deleteOffer(id: string) {
  const { data } = await api.delete(`/offers/${id}`)
  return data
}
