// Calendly API v2 Types

export interface CalendlyConfig {
  apiKey: string;
  baseUrl?: string;
}

export interface CalendlyUser {
  uri: string;
  name: string;
  slug: string;
  email: string;
  scheduling_url: string;
  timezone: string;
  avatar_url: string;
  created_at: string;
  updated_at: string;
  current_organization: string;
  resource_type: string;
}

export interface CalendlyEvent {
  uri: string;
  name: string;
  meeting_notes_plain: string;
  meeting_notes_html: string;
  status: 'active' | 'canceled';
  start_time: string;
  end_time: string;
  event_type: string;
  location: {
    type: string;
    location?: string;
    join_url?: string;
  };
  invitees_counter: {
    total: number;
    active: number;
    limit: number;
  };
  created_at: string;
  updated_at: string;
  event_memberships: Array<{
    user: string;
  }>;
  event_guests: Array<{
    email: string;
    created_at: string;
  }>;
  cancellation?: {
    canceled_by: string;
    reason: string;
    canceler_type: string;
  };
}

export interface CalendlyEventType {
  uri: string;
  name: string;
  active: boolean;
  slug: string;
  scheduling_url: string;
  duration: number;
  kind: 'solo' | 'group' | 'collective' | 'round_robin';
  pooling_type?: string;
  type: 'StandardEventType' | 'AdhocEventType';
  color: string;
  created_at: string;
  updated_at: string;
  internal_note: string;
  description_plain: string;
  description_html: string;
  profile: {
    type: string;
    name: string;
    owner: string;
  };
  secret: boolean;
  booking_method: string;
  custom_questions: Array<{
    name: string;
    type: string;
    position: number;
    enabled: boolean;
    required: boolean;
    answer_choices: string[];
    include_other: boolean;
  }>;
}

export interface CalendlyInvitee {
  uri: string;
  email: string;
  name: string;
  first_name: string;
  last_name: string;
  status: 'active' | 'canceled';
  timezone: string;
  event: string;
  created_at: string;
  updated_at: string;
  tracking: {
    utm_campaign?: string;
    utm_source?: string;
    utm_medium?: string;
    utm_content?: string;
    utm_term?: string;
    salesforce_uuid?: string;
  };
  text_reminder_number: string;
  rescheduled: boolean;
  old_invitee: string;
  new_invitee: string;
  cancel_url: string;
  reschedule_url: string;
  questions_and_answers: Array<{
    question: string;
    answer: string;
    position: number;
  }>;
  cancellation?: {
    canceled_by: string;
    reason: string;
  };
  payment?: {
    id: string;
    provider: string;
    amount: number;
    currency: string;
    terms: string;
    successful: boolean;
  };
  no_show?: {
    created_at: string;
  };
  reconfirmation?: {
    created_at: string;
    confirmed_at: string;
  };
}

export interface CalendlyOrganization {
  uri: string;
  name: string;
  slug: string;
  status: string;
  timezone: string;
  created_at: string;
  updated_at: string;
  resource_type: string;
}

export interface CalendlyOrganizationMembership {
  uri: string;
  role: 'owner' | 'admin' | 'user';
  user: {
    uri: string;
    name: string;
    slug: string;
    email: string;
    scheduling_url: string;
    timezone: string;
    avatar_url: string;
    created_at: string;
    updated_at: string;
  };
  organization: string;
  created_at: string;
  updated_at: string;
}

export interface CalendlyOrganizationInvitation {
  uri: string;
  organization: string;
  email: string;
  status: 'pending' | 'accepted' | 'declined' | 'revoked';
  created_at: string;
  updated_at: string;
  last_sent_at: string;
}

export interface CalendlySchedulingLink {
  booking_url: string;
  owner: string;
  owner_type: string;
  resource_type: string;
}

export interface CalendlyWebhookSubscription {
  uri: string;
  callback_url: string;
  created_at: string;
  updated_at: string;
  retry_started_at: string;
  state: 'active' | 'disabled';
  events: string[];
  scope: 'user' | 'organization';
  organization: string;
  user: string;
  creator: string;
}

export interface CalendlyAvailableTime {
  status: 'available';
  invitees_remaining: number;
  start_time: string;
  scheduling_url: string;
}

export interface CalendlyUserBusyTime {
  start_time: string;
  end_time: string;
  type: 'calendly' | 'busy_calendar';
  buffered: boolean;
}

export interface CalendlyRoutingForm {
  uri: string;
  name: string;
  status: 'published' | 'draft';
  published_version: number;
  organization: string;
  created_at: string;
  updated_at: string;
  questions: Array<{
    uuid: string;
    name: string;
    type: string;
    required: boolean;
    answer_choices?: Array<{
      uuid: string;
      label: string;
      position: number;
    }>;
  }>;
  routing_configurations: Array<{
    priority: number;
    rules: Array<{
      question_uuid: string;
      type: string;
      value: string;
    }>;
    routing_target: {
      type: string;
      target: string;
    };
  }>;
}

export interface CalendlyNoShow {
  uri: string;
  created_at: string;
}

export interface PaginationParams {
  count?: number;
  page_token?: string;
  sort?: string;
}

export interface PaginatedResponse<T> {
  collection: T[];
  pagination: {
    count: number;
    next_page?: string;
    previous_page?: string;
    next_page_token?: string;
    previous_page_token?: string;
  };
}

export interface CalendlyError {
  title: string;
  message: string;
  details?: Array<{
    parameter: string;
    message: string;
  }>;
}
