import api, { ApiResponse } from './api';

// Types
export interface AgentType {
  id: string;
  name: string;
  description: string | null;
  icon: string | null;
  isActive: boolean;
  sortOrder: number;
  createdAt: string;
  updatedAt: string;
  _count?: {
    agents: number;
  };
}

export interface CreateAgentTypeDto {
  name: string;
  description?: string;
  icon?: string;
  isActive?: boolean;
  sortOrder?: number;
}

export interface UpdateAgentTypeDto {
  name?: string;
  description?: string;
  icon?: string;
  isActive?: boolean;
  sortOrder?: number;
}

// Agent Types Service
class AgentTypesService {
  private basePath = '/agent-types';

  async getAll(includeInactive = false): Promise<AgentType[]> {
    const url = includeInactive
      ? `${this.basePath}?includeInactive=true`
      : this.basePath;
    const response = await api.get<ApiResponse<AgentType[]>>(url);
    return response.data.data;
  }

  async getById(id: string): Promise<AgentType> {
    const response = await api.get<ApiResponse<AgentType>>(`${this.basePath}/${id}`);
    return response.data.data;
  }

  async create(data: CreateAgentTypeDto): Promise<AgentType> {
    const response = await api.post<ApiResponse<AgentType>>(this.basePath, data);
    return response.data.data;
  }

  async update(id: string, data: UpdateAgentTypeDto): Promise<AgentType> {
    const response = await api.patch<ApiResponse<AgentType>>(`${this.basePath}/${id}`, data);
    return response.data.data;
  }

  async delete(id: string): Promise<void> {
    await api.delete(`${this.basePath}/${id}`);
  }
}

export const agentTypesService = new AgentTypesService();
