# Bayleys API Extension Settings

## Configuration Options

### Module Configuration

```php
'bayleys' => [
    'class' => 'PortalPeople\bayleys\Module',
    'baseUrl' => 'https://api.bayleys.com',
    'apiKey' => getenv('BAYLEYS_API_KEY'),
    'timeout' => 30,
    'retryAttempts' => 3,
]
```

## Environment Variables

| Variable | Description | Required | Default |
|----------|-------------|----------|---------|
| `BAYLEYS_API_KEY` | API key for Bayleys authentication | Yes | - |
| `BAYLEYS_API_URL` | Base URL for Bayleys API | No | `https://api.bayleys.com` |
| `BAYLEYS_TIMEOUT` | Request timeout in seconds | No | `30` |
| `BAYLEYS_RETRY_ATTEMPTS` | Number of retry attempts on failure | No | `3` |

## API Endpoints

### Resources

#### List Resources
```php
$client = Yii::$app->get('bayleys');
$resources = $client->listResources([
    'page' => 1,
    'limit' => 50,
]);
```

#### Get Resource
```php
$resource = $client->getResource($id);
```

#### Create Resource
```php
$resource = $client->createResource([
    'name' => 'Resource Name',
    'description' => 'Resource Description',
]);
```

#### Update Resource
```php
$resource = $client->updateResource($id, [
    'name' => 'Updated Name',
]);
```

#### Delete Resource
```php
$client->deleteResource($id);
```

## Error Handling

The extension provides comprehensive error handling:

```php
try {
    $resource = $client->getResource($id);
} catch (\PortalPeople\bayleys\exceptions\BayleysException $e) {
    Yii::error('Bayleys API Error: ' . $e->getMessage());
} catch (\Exception $e) {
    Yii::error('General Error: ' . $e->getMessage());
}
```

## Logging

Configure logging in your application config to capture Bayleys API activities:

```php
'log' => [
    'targets' => [
        [
            'class' => 'yii\log\FileTarget',
            'levels' => ['info', 'warning', 'error'],
            'logFile' => '@runtime/logs/bayleys.log',
            'categories' => ['PortalPeople\bayleys*'],
        ],
    ],
],
```

## Performance Considerations

- Use caching for frequently accessed resources
- Implement pagination for large result sets
- Consider rate limiting for API requests
- Monitor API response times and adjust timeout settings accordingly

## Security Best Practices

1. Never commit credentials to version control
2. Use environment variables for API keys
3. Rotate API keys regularly
4. Implement request validation and sanitization
5. Use HTTPS for all API communications
6. Log security-relevant events

## Troubleshooting

### Connection Timeout
- Check your network connectivity
- Verify the API URL is correct
- Increase the timeout value in configuration

### Authentication Failures
- Verify your API key is correct
- Check if your API key has expired
- Ensure the API key has appropriate permissions

### Rate Limiting
- Implement exponential backoff for retries
- Space out API requests appropriately
- Contact Bayleys support for rate limit increases
