import api from './api';

const base = '/warehouse';

const warehouseService = {
    // Summary
    getSummary:   ()         => api.get(`${base}/summary`).then(r => r.data),
    getViolations: ()        => api.get(`${base}/violations`).then(r => r.data),

    // Locations
    getLocations:    ()      => api.get(`${base}/locations`).then(r => r.data),
    createLocation:  (data)  => api.post(`${base}/locations`, data).then(r => r.data),
    updateLocation:  (id, d) => api.put(`${base}/locations/${id}`, d).then(r => r.data),
    deleteLocation:  (id)    => api.delete(`${base}/locations/${id}`).then(r => r.data),

    // Movements
    getMovements:    (params) => api.get(`${base}/movements`, { params }).then(r => r.data),
    createMovement:  (data)   => api.post(`${base}/movements`, data).then(r => r.data),

    // Stock thresholds
    getThresholds:   ()       => api.get(`${base}/thresholds`).then(r => r.data),
    upsertThreshold: (data)   => api.post(`${base}/thresholds`, data).then(r => r.data),
    deleteThreshold: (cat)    => api.delete(`${base}/thresholds/${encodeURIComponent(cat)}`).then(r => r.data),

    // Purchase orders
    getOrders:       (params) => api.get(`${base}/orders`, { params }).then(r => r.data),
    createOrder:     (data)   => api.post(`${base}/orders`, data).then(r => r.data),
    updateOrder:     (id, d)  => api.put(`${base}/orders/${id}`, d).then(r => r.data),
    deleteOrder:     (id)     => api.delete(`${base}/orders/${id}`).then(r => r.data),

    // QR Code URL
    getQrUrl:        (assetId) => `${api.defaults.baseURL}${base}/qr/${assetId}`,
};

export default warehouseService;
