import { sub } from 'date-fns'
import { formatDate } from './metrics';


export const getLogs = async function ({
    start = sub(new Date(), { hours: 12 }),
    end = new Date(),
    filter = ""
} = {}) {
    try {
        const data = await fetch(`http://localhost:8080/api/v1/metrics/log?filter=${filter}`, {
            "method": "GET",
            "headers": { "Accept": "application/json" }
        });

        const { success, payload } = await data.json();
        if (success) {
            return { payload, start, end, filter };
        }
        return { error: payload };
    } catch (error) {
        console.error(error);
        return { error };
    }
}
