/**
 * TypeScript types for Attio fetch implementation
 *
 * Shared param/result types are imported from the browser-safe location at
 * integration/types/attio.ts and re-exported here so existing imports
 * continue to work unchanged.
 *
 * Server-internal types (API responses, credentials) are defined locally.
 */

// Re-export all shared param/result types from browser-safe location
export * from '../../../../../types/attio'

// Import RecordId for use in server-internal response types below
import type { RecordId } from '../../../../../types/attio'

// ============================================================================
// Server-Only Types
// ============================================================================

/**
 * Attio credentials format
 * Only requires API key (Bearer token authentication)
 */
export interface AttioCredentials {
  apiKey: string
}

/**
 * Attio API response for record operations
 */
export interface AttioRecordResponse {
  data: {
    id: RecordId
    created_at: string
    web_url: string
    values: Record<string, unknown>
  }
}

/**
 * Attio API response for query operations
 */
export interface AttioQueryResponse {
  data: Array<{
    id: RecordId
    created_at: string
    web_url: string
    values: Record<string, unknown>
  }>
}

/**
 * Attio API error response
 */
export interface AttioErrorResponse {
  status_code: number
  type: string
  code: string
  message: string
}

// ============================================================================
// Attio API Response Types (for parsing)
// ============================================================================

export interface AttioObjectResponse {
  data: {
    id: { workspace_id: string; object_id: string }
    api_slug: string
    singular_noun: string
    plural_noun: string
    created_at: string
  }
}

export interface AttioObjectsListResponse {
  data: Array<{
    id: { workspace_id: string; object_id: string }
    api_slug: string
    singular_noun: string
    plural_noun: string
    created_at: string
  }>
}

export interface AttioAttributeResponse {
  data: {
    id: { workspace_id: string; object_id: string; attribute_id: string }
    api_slug: string
    title: string
    description?: string
    type: string
    is_system_attribute: boolean
    is_required: boolean
    is_unique: boolean
    is_multiselect: boolean
    is_archived: boolean
    config?: Record<string, unknown>
  }
}

export interface AttioAttributesListResponse {
  data: Array<{
    id: { workspace_id: string; object_id: string; attribute_id: string }
    api_slug: string
    title: string
    description?: string
    type: string
    is_system_attribute: boolean
    is_required: boolean
    is_unique: boolean
    is_multiselect: boolean
    is_archived: boolean
    config?: Record<string, unknown>
  }>
}

/**
 * Attio API response for note operations
 */
export interface AttioNoteResponse {
  data: {
    id: { workspace_id: string; note_id: string }
    parent_object: string
    parent_record_id: string
    title: string
    content_plaintext: string
    created_by_actor: { type: string; id: string }
    created_at: string
  }
}

/**
 * Attio API response for list notes
 */
export interface AttioNotesListResponse {
  data: Array<{
    id: { workspace_id: string; note_id: string }
    parent_object: string
    parent_record_id: string
    title: string
    content_plaintext: string
    created_by_actor: { type: string; id: string }
    created_at: string
  }>
}