/**
 * translation-service.js
 * API wrapper for Translation Dictionary endpoints
 */

import apiClient from './api-client.js';

class TranslationService {
  constructor() {
    this.baseUrl = '/translations';
  }

  // ========== Dictionary Operations ==========

  async listDictionaries(filters = {}) {
    const params = new URLSearchParams();
    if (filters.projectId) params.set('projectId', filters.projectId);
    if (filters.status) params.set('status', filters.status);
    if (filters.limit) params.set('limit', filters.limit);
    if (filters.offset) params.set('offset', filters.offset);

    const queryString = params.toString();
    const url = queryString ? `${this.baseUrl}?${queryString}` : this.baseUrl;
    return apiClient.request('GET', url);
  }

  async getDictionary(id) {
    return apiClient.request('GET', `${this.baseUrl}/${id}`);
  }

  async createDictionary(data) {
    return apiClient.request('POST', this.baseUrl, data);
  }

  async updateDictionary(id, data) {
    return apiClient.request('PUT', `${this.baseUrl}/${id}`, data);
  }

  async deleteDictionary(id) {
    return apiClient.request('DELETE', `${this.baseUrl}/${id}`);
  }

  // ========== Mapping Operations ==========

  async createMapping(dictionaryId, data) {
    return apiClient.request('POST', `${this.baseUrl}/${dictionaryId}/mappings`, data);
  }

  async updateMapping(dictionaryId, mappingId, data) {
    return apiClient.request('PUT', `${this.baseUrl}/${dictionaryId}/mappings/${mappingId}`, data);
  }

  async deleteMapping(dictionaryId, mappingId) {
    return apiClient.request('DELETE', `${this.baseUrl}/${dictionaryId}/mappings/${mappingId}`);
  }

  async bulkImportMappings(dictionaryId, mappings) {
    return apiClient.request('POST', `${this.baseUrl}/${dictionaryId}/mappings/bulk`, { mappings });
  }

  // ========== Validation & Analysis ==========

  async validateDictionary(id) {
    return apiClient.request('GET', `${this.baseUrl}/${id}/validate`);
  }

  async getCoverage(id) {
    return apiClient.request('GET', `${this.baseUrl}/${id}/coverage`);
  }

  async exportDictionary(id) {
    return apiClient.request('GET', `${this.baseUrl}/${id}/export`);
  }
}

export default new TranslationService();
