/**
 * Core Invitation Types
 * Internal types for the invitation system
 */

import type { User } from '../users/user'
import type { OrganizationMembership } from '../memberships/membership'

// Core internal invitation interface
export interface Invitation {
  id: string
  workosInvitationId: string
  email: string
  organizationId: string | null
  inviterUserId: string | null
  invitationState: 'pending' | 'accepted' | 'revoked' | 'expired'
  roleSlug: string | null
  invitationToken: string | null
  acceptInvitationUrl: string | null
  acceptedAt: string | null
  revokedAt: string | null
  expiresAt: string
  createdAt: string | null
  updatedAt: string | null
}

// Request/Response types for API
export interface SendInvitationRequest {
  email: string
  organizationId?: string
  roleSlug?: string
  expiresInDays?: number
  inviterUserId?: string
}

export interface ListInvitationsParams {
  organizationId?: string
  email?: string
  limit?: number
  before?: string
  after?: string
  order?: 'asc' | 'desc'
}

export interface AcceptanceResult {
  invitation: Invitation
  user?: User | null
  membership?: OrganizationMembership | null
}

export interface AcceptInvitationRequest {
  invitation_token: string
}

export interface InvitationListQuery {
  userId?: string
  organizationId?: string
  email?: string
  limit?: string
  before?: string
  after?: string
  order?: 'asc' | 'desc'
}

export interface InvitationSummaryResponse {
  totalInvitations: number
  pendingInvitations: number
  acceptedInvitations: number
  expiredInvitations: number
}

// Invitation with enriched details for UI
export interface InvitationWithDetails extends Invitation {
  organization?: {
    id: string
    name: string
    status?: string
  }
  inviter?: {
    id: string
    email: string
    firstName?: string | null
    lastName?: string | null
    profilePictureUrl?: string | null
  }
}
