# ALHP API Client

This directory contains a type-safe API client for the ALHP API, generated from the OpenAPI specification.

## Usage

### Importing

```typescript
// Import the API client and its functions
import { apiClient, getPackages, getStats } from '@/api';

// Import types
import type { components } from '@/api';
```

### Fetching Packages

```typescript
import { getPackages } from '@/api';
import type { components } from '@/api';

// Example: Get packages with filtering
async function fetchPackages() {
  try {
    const result = await getPackages({
      status: ['latest', 'building'],
      pkgbase: 'linux',
      exact: false,
      repo: 'core-x86-64-v3',
      offset: 0,
      limit: 50
    });
    
    // Access the packages
    const packages: components['schemas']['Package'][] = result.packages || [];
    const total: number = result.total || 0;
    
    return { packages, total };
  } catch (error) {
    console.error('Failed to fetch packages:', error);
    return { packages: [], total: 0 };
  }
}
```

### Fetching Stats

```typescript
import { getStats } from '@/api';
import type { components } from '@/api';

// Example: Get build statistics
async function fetchStats() {
  try {
    const stats = await getStats();
    
    // Access the stats
    const failedCount: number = stats.failed || 0;
    const ltoEnabled: number = stats.lto?.enabled || 0;
    
    return stats;
  } catch (error) {
    console.error('Failed to fetch stats:', error);
    return null;
  }
}
```

### Using the Raw API Client

If you need more control or want to use endpoints not covered by the utility functions, you can use the raw API client:

```typescript
import { apiClient } from '@/api';

// Example: Custom API call
async function customApiCall() {
  const { data, error } = await apiClient.GET('/packages', {
    params: {
      query: {
        // Your custom parameters
        status: ['latest'],
        limit: 10,
        offset: 0
      }
    }
  });
  
  if (error) {
    console.error('API error:', error);
    return null;
  }
  
  return data;
}
```

## Types

The API client uses types generated from the OpenAPI specification. The main types are:

- `components['schemas']['Package']`: Type for package data
- `components['schemas']['Stats']`: Type for statistics data

These types provide full TypeScript intellisense and type checking.
