/**
 * Attributes API Service
 */

import api from './api';
import type { 
  AttributesResponse, 
  ConvertAttributeRequest,
  ConvertAttributeResponse 
} from '../types/attribute';

/**
 * Get all attributes (global + local)
 */
export async function getAttributes(): Promise<AttributesResponse> {
  const { data } = await api.get<AttributesResponse>('/attributes');
  return data;
}

/**
 * Convert local attribute to global
 */
export async function convertAttribute(request: ConvertAttributeRequest): Promise<ConvertAttributeResponse> {
  console.log('[attributes.ts] Converting attribute:', request);
  console.log('[attributes.ts] API baseURL:', api.defaults.baseURL);
  console.log('[attributes.ts] Full URL:', api.defaults.baseURL + '/attributes/convert');
  const { data } = await api.post<ConvertAttributeResponse>('/attributes/convert', request);
  console.log('[attributes.ts] Conversion response:', data);
  return data;
}
