import { get, post, del } from './client';

/**
 * Invitation API Types
 */
export interface CreateInvitationRequest {
  email: string;
  firstName: string;
  lastName: string;
  role: 'MANAGER' | 'USER' | 'VIEWER';
}

export interface InvitationResponse {
  id: string;
  email: string;
  firstName: string;
  lastName: string;
  role: string;
  organizationId: string;
  invitedById: string;
  token: string;
  expiresAt: string;
  isUsed: boolean;
  usedAt?: string;
  createdAt: string;
}

/**
 * Create a new invitation
 * Sends an email to the invited user with a registration link
 */
export async function createInvitation(data: CreateInvitationRequest): Promise<InvitationResponse> {
  return post<InvitationResponse>('/api/v1/invitations', data);
}

/**
 * Verify an invitation token
 * Checks if the token is valid and not expired
 */
export async function verifyInvitation(token: string): Promise<InvitationResponse> {
  return get<InvitationResponse>(`/api/v1/invitations/verify/${token}`, false);
}

/**
 * List all invitations for the current organization
 */
export async function listInvitations(): Promise<InvitationResponse[]> {
  return get<InvitationResponse[]>('/api/v1/invitations');
}

/**
 * Cancel (delete) a pending invitation
 */
export async function cancelInvitation(id: string): Promise<void> {
  return del<void>(`/api/v1/invitations/${id}`);
}
