/**
 * Basecamp 4 API Type Definitions
 */

export interface BasecampConfig {
  accountId: string;
  accessToken: string;
  userAgent?: string;
}

export interface PaginationLinks {
  next?: string;
  prev?: string;
}

export interface BasecampError {
  error: string;
  message?: string;
}

// Base types
export interface Person {
  id: number;
  attachable_sgid: string;
  name: string;
  email_address: string;
  personable_type: string;
  title: string;
  bio: string | null;
  location: string | null;
  created_at: string;
  updated_at: string;
  admin: boolean;
  owner: boolean;
  client: boolean;
  employee: boolean;
  time_zone: string;
  avatar_url: string;
  company: {
    id: number;
    name: string;
  };
}

export interface Project {
  id: number;
  status: 'active' | 'archived' | 'trashed';
  created_at: string;
  updated_at: string;
  name: string;
  description: string;
  purpose: string;
  clients_enabled: boolean;
  bookmark_url: string;
  url: string;
  app_url: string;
  dock: DockItem[];
  bookmarked: boolean;
}

export interface DockItem {
  id: number;
  title: string;
  name: string;
  enabled: boolean;
  position: number;
  url: string;
  app_url: string;
}

export interface Todolist {
  id: number;
  status: 'active' | 'archived' | 'trashed';
  visible_to_clients: boolean;
  created_at: string;
  updated_at: string;
  title: string;
  inherits_status: boolean;
  type: 'Todolist';
  url: string;
  app_url: string;
  bookmark_url: string;
  subscription_url: string;
  comments_count: number;
  comments_url: string;
  parent: {
    id: number;
    title: string;
    type: string;
    url: string;
    app_url: string;
  };
  bucket: {
    id: number;
    name: string;
    type: 'Project';
  };
  creator: Person;
  description: string;
  completed: boolean;
  completed_ratio: string;
  name: string;
  todos_url: string;
  groups_url: string;
  app_todos_url: string;
}

export interface Todo {
  id: number;
  status: 'active' | 'archived' | 'trashed';
  visible_to_clients: boolean;
  created_at: string;
  updated_at: string;
  title: string;
  inherits_status: boolean;
  type: 'Todo';
  url: string;
  app_url: string;
  bookmark_url: string;
  subscription_url: string;
  comments_count: number;
  comments_url: string;
  parent: {
    id: number;
    title: string;
    type: string;
    url: string;
    app_url: string;
  };
  bucket: {
    id: number;
    name: string;
    type: 'Project';
  };
  creator: Person;
  description: string;
  completed: boolean;
  content: string;
  starts_on: string | null;
  due_on: string | null;
  assignees: Person[];
  completion_url: string;
  completion_subscriber_ids: number[];
  position: number;
}

export interface Message {
  id: number;
  status: 'active' | 'archived' | 'trashed';
  visible_to_clients: boolean;
  created_at: string;
  updated_at: string;
  title: string;
  inherits_status: boolean;
  type: 'Message';
  url: string;
  app_url: string;
  bookmark_url: string;
  subscription_url: string;
  comments_count: number;
  comments_url: string;
  parent: {
    id: number;
    title: string;
    type: string;
    url: string;
    app_url: string;
  };
  bucket: {
    id: number;
    name: string;
    type: 'Project';
  };
  creator: Person;
  subject: string;
  content: string;
  category_id: number | null;
}

export interface Comment {
  id: number;
  status: 'active' | 'trashed';
  visible_to_clients: boolean;
  created_at: string;
  updated_at: string;
  title: string;
  inherits_status: boolean;
  type: 'Comment';
  url: string;
  app_url: string;
  bookmark_url: string;
  subscription_url: string;
  parent: {
    id: number;
    title: string;
    type: string;
    url: string;
    app_url: string;
  };
  bucket: {
    id: number;
    name: string;
    type: 'Project';
  };
  creator: Person;
  content: string;
}

export interface CampfireLine {
  id: number;
  status: 'active';
  visible_to_clients: boolean;
  created_at: string;
  updated_at: string;
  title: string;
  inherits_status: boolean;
  type: 'Chat::Line';
  url: string;
  app_url: string;
  bookmark_url: string;
  subscription_url: string;
  parent: {
    id: number;
    title: string;
    type: string;
    url: string;
    app_url: string;
  };
  bucket: {
    id: number;
    name: string;
    type: 'Project';
  };
  creator: Person;
  content: string;
}

export interface Schedule {
  id: number;
  status: 'active' | 'archived' | 'trashed';
  visible_to_clients: boolean;
  created_at: string;
  updated_at: string;
  title: string;
  inherits_status: boolean;
  type: 'Schedule';
  url: string;
  app_url: string;
  bookmark_url: string;
  subscription_url: string;
  entries_count: number;
  entries_url: string;
  bucket: {
    id: number;
    name: string;
    type: 'Project';
  };
  creator: Person;
}

export interface ScheduleEntry {
  id: number;
  status: 'active' | 'archived' | 'trashed';
  visible_to_clients: boolean;
  created_at: string;
  updated_at: string;
  title: string;
  inherits_status: boolean;
  type: 'Schedule::Entry';
  url: string;
  app_url: string;
  bookmark_url: string;
  subscription_url: string;
  comments_count: number;
  comments_url: string;
  parent: {
    id: number;
    title: string;
    type: string;
    url: string;
    app_url: string;
  };
  bucket: {
    id: number;
    name: string;
    type: 'Project';
  };
  creator: Person;
  summary: string;
  description: string;
  starts_at: string;
  ends_at: string;
  all_day: boolean;
  participant_ids: number[];
}

export interface Document {
  id: number;
  status: 'active' | 'archived' | 'trashed';
  visible_to_clients: boolean;
  created_at: string;
  updated_at: string;
  title: string;
  inherits_status: boolean;
  type: 'Document';
  url: string;
  app_url: string;
  bookmark_url: string;
  subscription_url: string;
  comments_count: number;
  comments_url: string;
  parent: {
    id: number;
    title: string;
    type: string;
    url: string;
    app_url: string;
  };
  bucket: {
    id: number;
    name: string;
    type: 'Project';
  };
  creator: Person;
  content: string;
}

export interface Upload {
  id: number;
  status: 'active' | 'archived' | 'trashed';
  visible_to_clients: boolean;
  created_at: string;
  updated_at: string;
  title: string;
  inherits_status: boolean;
  type: 'Upload';
  url: string;
  app_url: string;
  bookmark_url: string;
  subscription_url: string;
  comments_count: number;
  comments_url: string;
  parent: {
    id: number;
    title: string;
    type: string;
    url: string;
    app_url: string;
  };
  bucket: {
    id: number;
    name: string;
    type: 'Project';
  };
  creator: Person;
  description: string;
  filename: string;
  filesize: number;
  content_type: string;
  download_url: string;
  byte_size: number;
  width: number | null;
  height: number | null;
}

export interface Questionnaire {
  id: number;
  status: 'active' | 'archived' | 'trashed';
  visible_to_clients: boolean;
  created_at: string;
  updated_at: string;
  title: string;
  inherits_status: boolean;
  type: 'Questionnaire';
  url: string;
  app_url: string;
  bookmark_url: string;
  subscription_url: string;
  bucket: {
    id: number;
    name: string;
    type: 'Project';
  };
  creator: Person;
  questions_count: number;
  questions_url: string;
}

export interface Question {
  id: number;
  status: 'active';
  created_at: string;
  updated_at: string;
  title: string;
  inherits_status: boolean;
  type: 'Question';
  url: string;
  app_url: string;
  parent: {
    id: number;
    title: string;
    type: string;
    url: string;
    app_url: string;
  };
  bucket: {
    id: number;
    name: string;
    type: 'Project';
  };
  creator: Person;
  paused: boolean;
  schedule: string;
  answers_count: number;
  answers_url: string;
}

export interface Answer {
  id: number;
  status: 'active';
  visible_to_clients: boolean;
  created_at: string;
  updated_at: string;
  title: string;
  inherits_status: boolean;
  type: 'Answer';
  url: string;
  app_url: string;
  bookmark_url: string;
  subscription_url: string;
  comments_count: number;
  comments_url: string;
  parent: {
    id: number;
    title: string;
    type: string;
    url: string;
    app_url: string;
  };
  bucket: {
    id: number;
    name: string;
    type: 'Project';
  };
  creator: Person;
  content: string;
  group_on: string;
}

export interface Webhook {
  id: number;
  url: string;
  payload_url: string;
  types: string[];
  active: boolean;
  created_at: string;
  updated_at: string;
}

export interface Recording {
  id: number;
  status: 'active' | 'archived' | 'trashed';
  visible_to_clients: boolean;
  created_at: string;
  updated_at: string;
  title: string;
  inherits_status: boolean;
  type: string;
  url: string;
  app_url: string;
  bookmark_url: string;
  subscription_url: string;
  bucket: {
    id: number;
    name: string;
    type: 'Project';
  };
  creator: Person;
}

// Request/Response types
export interface CreateProjectRequest {
  name: string;
  description?: string;
}

export interface UpdateProjectRequest {
  name?: string;
  description?: string;
}

export interface CreateTodolistRequest {
  name: string;
  description?: string;
}

export interface CreateTodoRequest {
  content: string;
  description?: string;
  assignee_ids?: number[];
  completion_subscriber_ids?: number[];
  notify?: boolean;
  due_on?: string;
  starts_on?: string;
}

export interface UpdateTodoRequest {
  content?: string;
  description?: string;
  assignee_ids?: number[];
  completion_subscriber_ids?: number[];
  notify?: boolean;
  due_on?: string;
  starts_on?: string;
}

export interface CreateMessageRequest {
  subject: string;
  content: string;
  category_id?: number;
}

export interface CreateCommentRequest {
  content: string;
}

export interface CreateCampfireLineRequest {
  content: string;
}

export interface CreateScheduleEntryRequest {
  summary: string;
  description?: string;
  starts_at: string;
  ends_at?: string;
  all_day?: boolean;
  participant_ids?: number[];
  notify?: boolean;
}

export interface UpdateScheduleEntryRequest {
  summary?: string;
  description?: string;
  starts_at?: string;
  ends_at?: string;
  all_day?: boolean;
  participant_ids?: number[];
  notify?: boolean;
}

export interface CreateDocumentRequest {
  title: string;
  content: string;
}

export interface UpdateDocumentRequest {
  title?: string;
  content?: string;
}

export interface CreateWebhookRequest {
  payload_url: string;
  types?: string[];
}

export interface UpdateWebhookRequest {
  payload_url?: string;
  types?: string[];
}
