import client from './client'

export interface Plant {
  id?: number
  nom_commun: string
  nom_botanique?: string
  variete?: string
  famille?: string
  categorie?: string  // potager|fleur|arbre|arbuste
  tags?: string
  type_plante?: string
  besoin_eau?: string
  besoin_soleil?: string
  espacement_cm?: number
  temp_min_c?: number
  hauteur_cm?: number
  plantation_mois?: string
  recolte_mois?: string
  semis_interieur_mois?: string
  semis_exterieur_mois?: string
  maladies_courantes?: string
  astuces_culture?: string
  url_reference?: string
  notes?: string
}

export const plantsApi = {
  list: (categorie?: string) => client.get<Plant[]>('/api/plants', { params: categorie ? { categorie } : {} }).then(r => r.data),
  get: (id: number) => client.get<Plant>(`/api/plants/${id}`).then(r => r.data),
  create: (p: Partial<Plant>) => client.post<Plant>('/api/plants', p).then(r => r.data),
  update: (id: number, p: Partial<Plant>) => client.put<Plant>(`/api/plants/${id}`, p).then(r => r.data),
  delete: (id: number) => client.delete(`/api/plants/${id}`),
}
