// Wrike API v4 Types

export interface WrikeConfig {
  apiToken: string;
  baseUrl?: string;
}

export interface WrikeTask {
  id: string;
  accountId: string;
  title: string;
  description?: string;
  briefDescription?: string;
  parentIds: string[];
  superParentIds?: string[];
  sharedIds?: string[];
  responsibleIds: string[];
  status: string;
  importance: 'High' | 'Normal' | 'Low';
  createdDate: string;
  updatedDate: string;
  dates?: {
    type: string;
    duration?: number;
    start?: string;
    due?: string;
  };
  scope: string;
  authorIds: string[];
  customStatusId?: string;
  hasAttachments: boolean;
  permalink: string;
  priority?: string;
  followedByMe?: boolean;
  followerIds?: string[];
  superTaskIds?: string[];
  subTaskIds?: string[];
  dependencyIds?: string[];
  metadata?: any[];
  customFields?: CustomFieldValue[];
}

export interface WrikeFolder {
  id: string;
  accountId: string;
  title: string;
  createdDate: string;
  updatedDate: string;
  briefDescription?: string;
  description?: string;
  sharedIds: string[];
  parentIds: string[];
  childIds: string[];
  superParentIds?: string[];
  scope: string;
  hasAttachments: boolean;
  permalink: string;
  workflowId?: string;
  metadata?: any[];
  customFields?: CustomFieldValue[];
  customColumnIds?: string[];
  project?: WrikeProject;
}

export interface WrikeProject {
  authorId: string;
  ownerIds: string[];
  status: 'Green' | 'Yellow' | 'Red' | 'Completed' | 'OnHold' | 'Cancelled';
  customStatusId?: string;
  startDate?: string;
  endDate?: string;
  createdDate: string;
  completedDate?: string;
  contractType?: string;
}

export interface WrikeSpace {
  id: string;
  title: string;
  avatarUrl?: string;
  accessType: 'Personal' | 'Private' | 'Public';
  archived: boolean;
  guestRoleId?: string;
  defaultProjectWorkflowId?: string;
  defaultTaskWorkflowId?: string;
}

export interface WrikeContact {
  id: string;
  firstName: string;
  lastName: string;
  type: 'Person' | 'Group';
  profiles: {
    accountId: string;
    email?: string;
    role: string;
    external: boolean;
    admin: boolean;
    owner: boolean;
  }[];
  avatarUrl?: string;
  timezone?: string;
  locale?: string;
  deleted: boolean;
  me?: boolean;
  memberIds?: string[];
  metadata?: any[];
  myTeam?: boolean;
  title?: string;
  companyName?: string;
  phone?: string;
  location?: string;
}

export interface WrikeComment {
  id: string;
  authorId: string;
  text: string;
  updatedDate: string;
  createdDate: string;
  taskId?: string;
  folderId?: string;
}

export interface WrikeTimelog {
  id: string;
  taskId: string;
  userId: string;
  categoryId?: string;
  hours: number;
  createdDate: string;
  updatedDate: string;
  trackedDate: string;
  comment?: string;
}

export interface WrikeAttachment {
  id: string;
  authorId: string;
  name: string;
  createdDate: string;
  version: number;
  type: string;
  contentType?: string;
  size: number;
  taskId?: string;
  folderId?: string;
  commentId?: string;
  url?: string;
  previewUrl?: string;
}

export interface WrikeWorkflow {
  id: string;
  name: string;
  standard: boolean;
  hidden: boolean;
  customStatuses: WrikeCustomStatus[];
}

export interface WrikeCustomStatus {
  id: string;
  name: string;
  standardName: boolean;
  color: string;
  standard: boolean;
  group: 'Active' | 'Completed' | 'Deferred' | 'Cancelled';
  hidden: boolean;
}

export interface WrikeCustomField {
  id: string;
  accountId: string;
  title: string;
  type: 'Text' | 'DropDown' | 'Numeric' | 'Currency' | 'Percentage' | 'Date' | 'Duration' | 'Checkbox' | 'Contacts' | 'Multiple';
  sharedIds?: string[];
  settings?: any;
}

export interface CustomFieldValue {
  id: string;
  value: any;
}

export interface WrikeApproval {
  id: string;
  authorId: string;
  title: string;
  description?: string;
  status: 'Pending' | 'Approved' | 'Rejected' | 'Cancelled';
  dueDate?: string;
  finishedDate?: string;
  decisions: {
    userId: string;
    decision: 'Pending' | 'Approved' | 'Rejected';
    updatedDate: string;
    comment?: string;
  }[];
  taskId?: string;
  folderId?: string;
}

export interface WrikeGroup {
  id: string;
  accountId: string;
  title: string;
  memberIds: string[];
  childIds: string[];
  parentIds: string[];
  avatarUrl?: string;
  myTeam: boolean;
  metadata?: any[];
}

export interface WrikeInvitation {
  id: string;
  accountId: string;
  firstName: string;
  lastName: string;
  email: string;
  status: 'Pending' | 'Accepted' | 'Declined' | 'Cancelled';
  inviterUserId: string;
  invitationDate: string;
  resolvedDate?: string;
  role: string;
  external: boolean;
}

export interface WrikeWebhook {
  id: string;
  accountId: string;
  hookUrl: string;
  folderId?: string;
  taskId?: string;
  status: 'Active' | 'Suspended';
}

export interface WrikeDependency {
  id: string;
  predecessorId: string;
  successorId: string;
  relationType: 'StartToStart' | 'StartToFinish' | 'FinishToStart' | 'FinishToFinish';
}

export interface WrikeApiResponse<T> {
  kind: string;
  data: T[];
}

export interface WrikeError {
  errorDescription: string;
  error: string;
}

export interface PaginationOptions {
  limit?: number;
  pageSize?: number;
  nextPageToken?: string;
}

export interface TaskQueryOptions extends PaginationOptions {
  descendants?: boolean;
  title?: string;
  status?: string;
  importance?: string;
  startDate?: string;
  dueDate?: string;
  scheduledDate?: string;
  createdDate?: string;
  updatedDate?: string;
  completedDate?: string;
  authors?: string[];
  responsibles?: string[];
  sortField?: string;
  sortOrder?: 'Asc' | 'Desc';
  subTasks?: boolean;
  fields?: string[];
  customField?: Record<string, any>;
}

export interface FolderQueryOptions extends PaginationOptions {
  descendants?: boolean;
  project?: boolean;
  deleted?: boolean;
  updatedDate?: string;
  customField?: Record<string, any>;
  fields?: string[];
}
