import apiClient from '../../../shared/services/apiClient';

export interface APIKey {
  id: number;
  name: string;
  key_prefix: string;
  scopes: string[];
  rate_limit: number;
  is_active: boolean;
  last_used_at?: string;
  expires_at?: string;
  description?: string;
  created_at: string;
}

export interface CreateAPIKeyData {
  name: string;
  scopes: string[];
  description?: string;
  rate_limit?: number;
  expires_at?: string;
}

export interface UpdateAPIKeyData {
  name?: string;
  scopes?: string[];
  description?: string;
  rate_limit?: number;
  expires_at?: string;
}

class APIKeyService {
  async createAPIKey(data: CreateAPIKeyData) {
    const response = await apiClient.post('/api-keys', data);
    return response.data;
  }

  async getAPIKeys() {
    const response = await apiClient.get('/api-keys');
    return response.data;
  }

  async updateAPIKey(keyId: number, data: UpdateAPIKeyData) {
    const response = await apiClient.put(`/api-keys/${keyId}`, data);
    return response.data;
  }

  async revokeAPIKey(keyId: number) {
    const response = await apiClient.delete(`/api-keys/${keyId}`);
    return response.data;
  }
}

export default new APIKeyService();

