import { apiGet, apiPost } from "../client";

function safeId(id) {
  return encodeURIComponent(String(id));
}

export const firmwaresApi = {
  async list() {
    return apiGet("/api/v1/firmwares");
  },

  async detail(id) {
    return apiGet(`/api/v1/firmwares/id/${safeId(id)}`);
  },

  async refresh() {
    return apiPost("/api/v1/firmwares/refresh");
  },

  async deviceCompatibility(deviceId) {
    return apiGet(`/api/v1/devices/id/${safeId(deviceId)}/firmware-compatibility`);
  },

  async updateDeviceFirmware(deviceId, firmwareId) {
    return apiPost("/api/v1/devices/update-firmware", {
      device_id: deviceId,
      firmware_id: firmwareId,
    });
  },
};
