import { api } from './http';

export interface Team {
  id: string;
  name: string;
  ownerId: string;
  createdAt: number;
  myRole?: 'owner' | 'admin' | 'member';
  members?: { id: string; email: string; name: string; role: string; joinedAt: number }[];
  agentCount?: number;
}

export const TeamAPI = {
  list: () => api.get<Team[]>('/teams').then((r) => r.data),
  detail: (id: string) => api.get<Team>(`/teams/${id}`).then((r) => r.data),
  create: (name: string) => api.post<Team>('/teams', { name }).then((r) => r.data),
  rename: (id: string, name: string) => api.put(`/teams/${id}`, { name }).then((r) => r.data),
  remove: (id: string) => api.delete(`/teams/${id}`).then((r) => r.data),
  removeMember: (id: string, userId: string) => api.delete(`/teams/${id}/members/${userId}`).then((r) => r.data)
};

