/**
 * Delivery-log resource.
 */

import { get, post, query } from './client';

export const fetchLogs = ( filters = {}, page = 1, perPage = 20 ) =>
	get( `/logs${ query( { ...filters, page, per_page: perPage } ) }` );

export const fetchLog = ( id ) => get( `/logs/${ id }` );

export const fetchStats = ( days = 30 ) =>
	get( `/logs/stats${ query( { days } ) }` );

export const retryLog = ( id ) => post( `/logs/${ id }/retry`, {} );

export const retryFailed = ( filters = {}, limit = 25 ) =>
	post( `/logs/retry-failed${ query( filters ) }`, { limit } );

export const exportLogs = ( filters = {} ) =>
	get( `/logs/export${ query( filters ) }` );

export const purgeLogs = ( days ) => post( '/logs/purge', { days } );
