export const mockApiClient = {
  get: jest.fn(),
  post: jest.fn(),
  put: jest.fn(),
  delete: jest.fn(),
}

export const setupApiMock = (method: 'get' | 'post' | 'put' | 'delete', response: any, error?: Error) => {
  const mock = error
    ? Promise.reject(error)
    : Promise.resolve({ success: true, data: response })

  mockApiClient[method].mockResolvedValueOnce(mock)
  return mock
}

export const resetApiMocks = () => {
  Object.values(mockApiClient).forEach((mock) => {
    if (jest.isMockFunction(mock)) {
      mock.mockReset()
    }
  })
}
