import { get, post, patch, del } from './client.js';

export async function fetchContainers(params = {}) {
  const query = new URLSearchParams(params).toString();
  return get(query ? `/api/specimen/container?${query}` : '/api/specimen/container');
}

export async function fetchContainer(id) {
  return get(`/api/specimen/container/${id}`);
}

export async function createContainer(data) {
  const payload = {
    ConCode: data.ConCode,
    ConName: data.ConName,
    ConDesc: data.ConDesc,
    ConClass: data.ConClass,
    Additive: data.Additive,
    Color: data.Color,
  };
  return post('/api/specimen/container', payload);
}

export async function updateContainer(id, data) {
  const payload = {
    ConCode: data.ConCode,
    ConName: data.ConName,
    ConDesc: data.ConDesc,
    ConClass: data.ConClass,
    Additive: data.Additive,
    Color: data.Color,
  };
  return patch(`/api/specimen/container/${id}`, payload);
}

export async function deleteContainer(id) {
  return del('/api/specimen/container', { body: JSON.stringify({ ConDefID: id }) });
}
