{{!-- SmartStack API Client Template --}}
{{!-- Generates type-safe API client with NavRoute integration --}}

/**
 * {{name}} API Client
 *
 * Auto-generated by SmartStack MCP - DO NOT EDIT MANUALLY
 * NavRoute: {{navRoute}}
 * API Path: {{apiPath}}
 */

import { getRoute } from '../routes/navRoutes.generated';
import { apiClient } from '../lib/apiClient';
import type {
  {{name}},
  {{name}}CreateRequest,
  {{name}}UpdateRequest,
  {{name}}ListResponse,
  PaginatedRequest,
  PaginatedResponse
} from '../types/{{nameLower}}';

const ROUTE = getRoute('{{navRoute}}');

export const {{nameLower}}Api = {
{{#if includeGetAll}}
  /**
   * Get all {{name}}s with pagination
   */
  async getAll(params?: PaginatedRequest): Promise<PaginatedResponse<{{name}}>> {
    const response = await apiClient.get<{{name}}ListResponse>(ROUTE.api, { params });
    return response.data;
  },

{{/if}}
{{#if includeGetById}}
  /**
   * Get {{name}} by ID
   */
  async getById(id: string): Promise<{{name}}> {
    const response = await apiClient.get<{{name}}>(`${ROUTE.api}/${id}`);
    return response.data;
  },

{{/if}}
{{#if includeCreate}}
  /**
   * Create new {{name}}
   */
  async create(data: {{name}}CreateRequest): Promise<{{name}}> {
    const response = await apiClient.post<{{name}}>(ROUTE.api, data);
    return response.data;
  },

{{/if}}
{{#if includeUpdate}}
  /**
   * Update existing {{name}}
   */
  async update(id: string, data: {{name}}UpdateRequest): Promise<{{name}}> {
    const response = await apiClient.put<{{name}}>(`${ROUTE.api}/${id}`, data);
    return response.data;
  },

{{/if}}
{{#if includeDelete}}
  /**
   * Delete {{name}}
   */
  async delete(id: string): Promise<void> {
    await apiClient.delete(`${ROUTE.api}/${id}`);
  },

{{/if}}
{{#if includeSearch}}
  /**
   * Search {{name}}s
   */
  async search(query: string, params?: PaginatedRequest): Promise<PaginatedResponse<{{name}}>> {
    const response = await apiClient.get<{{name}}ListResponse>(`${ROUTE.api}/search`, {
      params: { q: query, ...params }
    });
    return response.data;
  },

{{/if}}
{{#if includeExport}}
  /**
   * Export {{name}}s to file
   */
  async export(format: 'csv' | 'xlsx' | 'pdf' = 'xlsx'): Promise<Blob> {
    const response = await apiClient.get(`${ROUTE.api}/export`, {
      params: { format },
      responseType: 'blob'
    });
    return response.data;
  },

{{/if}}
  /**
   * Get the NavRoute configuration for this API
   */
  getRoute() {
    return ROUTE;
  },

  /**
   * Check if user has permission to access this API
   */
  hasPermission(userPermissions: string[]): boolean {
    if (ROUTE.permissions.length === 0) return true;
    return ROUTE.permissions.some(p => userPermissions.includes(p));
  },
};

export default {{nameLower}}Api;
