import client from './client'

export interface PlantVariety {
  id?: number
  nom_commun: string
  nom_botanique?: string
  variete?: string
  famille?: string
  type_plante?: string
  besoin_eau?: string
  espacement_cm?: number
  plantation_mois?: string
  recolte_mois?: string
  notes?: string
}

export const varietiesApi = {
  list: () => client.get<PlantVariety[]>('/api/varieties').then(r => r.data),
  get: (id: number) => client.get<PlantVariety>(`/api/varieties/${id}`).then(r => r.data),
  create: (v: Partial<PlantVariety>) => client.post<PlantVariety>('/api/varieties', v).then(r => r.data),
  update: (id: number, v: Partial<PlantVariety>) => client.put<PlantVariety>(`/api/varieties/${id}`, v).then(r => r.data),
  delete: (id: number) => client.delete(`/api/varieties/${id}`),
}
