import { api } from './api';

export interface AusruestungTyp {
  id: number;
  name: string;
  beschreibung?: string;
  icon?: string;
}

export const ausruestungTypenApi = {
  getAll: async (): Promise<AusruestungTyp[]> => {
    const r = await api.get('/api/ausruestung-typen');
    return r.data.data ?? r.data;
  },
  getById: async (id: number): Promise<AusruestungTyp> => {
    const r = await api.get(`/api/ausruestung-typen/${id}`);
    return r.data.data ?? r.data;
  },
  create: async (data: { name: string; beschreibung?: string; icon?: string }): Promise<AusruestungTyp> => {
    const r = await api.post('/api/ausruestung-typen', data);
    return r.data.data ?? r.data;
  },
  update: async (id: number, data: Partial<{ name: string; beschreibung: string; icon: string }>): Promise<AusruestungTyp> => {
    const r = await api.patch(`/api/ausruestung-typen/${id}`, data);
    return r.data.data ?? r.data;
  },
  delete: async (id: number): Promise<void> => {
    await api.delete(`/api/ausruestung-typen/${id}`);
  },
  getTypesForEquipment: async (ausruestungId: string): Promise<AusruestungTyp[]> => {
    const r = await api.get(`/api/ausruestung-typen/equipment/${ausruestungId}`);
    return r.data.data ?? r.data;
  },
  setTypesForEquipment: async (ausruestungId: string, typIds: number[]): Promise<void> => {
    await api.put(`/api/ausruestung-typen/equipment/${ausruestungId}`, { typIds });
  },
};
