/**
 * Integration types for external services
 */

/** Supported integration types */
export type IntegrationType =
  | 'plentyone'
  | 'zulip'
  | 'todoist'
  | 'freescout'
  | 'nextcloud'
  | 'ecodms'
  | 'gembadocs';

/** Integration connection status */
export type IntegrationStatus = 'connected' | 'disconnected' | 'error' | 'configuring';

/** Base integration configuration */
export interface IntegrationConfig {
  id: string;
  type: IntegrationType;
  name: string;
  enabled: boolean;
  status: IntegrationStatus;
  lastSync?: Date;
  lastError?: string;
  syncInterval: number; // in minutes
  createdAt: Date;
  updatedAt: Date;
}

/** Integration credentials (masked for display) */
export interface IntegrationCredentials {
  apiUrl?: string;
  apiKey?: string;
  username?: string;
  password?: string;
  token?: string;
  clientId?: string;
  clientSecret?: string;
}

// ============================================
// PlentyONE Types
// ============================================

/** Order status in PlentyONE */
export type OrderStatus =
  | 'new'
  | 'processing'
  | 'shipped'
  | 'delivered'
  | 'cancelled'
  | 'returned';

/** PlentyONE Order */
export interface PlentyOrder {
  id: string;
  orderNumber: string;
  status: OrderStatus;
  customerName: string;
  customerEmail: string;
  totalAmount: number;
  currency: string;
  itemCount: number;
  createdAt: Date;
  updatedAt: Date;
  shippingAddress?: {
    street: string;
    city: string;
    postalCode: string;
    country: string;
  };
}

// ============================================
// ZULIP Types
// ============================================

/** ZULIP stream */
export interface ZulipStream {
  id: number;
  name: string;
  description?: string;
  isPrivate: boolean;
}

/** ZULIP message */
export interface ZulipMessage {
  id: number;
  streamId: number;
  streamName: string;
  topic: string;
  senderId: number;
  senderName: string;
  senderAvatarUrl?: string;
  content: string;
  timestamp: Date;
  isRead: boolean;
}

/** ZULIP unread counts */
export interface ZulipUnreadCount {
  streamId: number;
  streamName: string;
  count: number;
}

// ============================================
// Todoist Types
// ============================================

/** Todoist task priority */
export type TodoistPriority = 1 | 2 | 3 | 4;

/** Todoist task */
export interface TodoistTask {
  id: string;
  content: string;
  description?: string;
  projectId?: string;
  projectName?: string;
  priority: TodoistPriority;
  dueDate?: Date;
  dueString?: string;
  isCompleted: boolean;
  labels: string[];
  createdAt: Date;
}

/** Todoist project */
export interface TodoistProject {
  id: string;
  name: string;
  color: string;
  isInbox: boolean;
}

// ============================================
// FreeScout Types
// ============================================

/** Ticket priority */
export type TicketPriority = 'low' | 'medium' | 'high' | 'urgent';

/** Ticket status */
export type TicketStatus = 'open' | 'pending' | 'resolved' | 'closed';

/** FreeScout ticket */
export interface FreeScoutTicket {
  id: string;
  number: number;
  subject: string;
  status: TicketStatus;
  priority: TicketPriority;
  customerName: string;
  customerEmail: string;
  assigneeName?: string;
  assigneeAvatarUrl?: string;
  replyCount: number;
  lastReplyAt?: Date;
  createdAt: Date;
  updatedAt: Date;
}

// ============================================
// Nextcloud Types
// ============================================

/** Nextcloud file type */
export type NextcloudFileType = 'file' | 'folder';

/** Nextcloud file */
export interface NextcloudFile {
  id: string;
  name: string;
  path: string;
  type: NextcloudFileType;
  mimeType?: string;
  size: number;
  modifiedAt: Date;
  downloadUrl?: string;
  previewUrl?: string;
}

// ============================================
// ecoDMS Types
// ============================================

/** ecoDMS document */
export interface EcoDmsDocument {
  id: string;
  title: string;
  fileName: string;
  fileType: string;
  fileSize: number;
  classification: string;
  tags: string[];
  createdBy: string;
  createdAt: Date;
  modifiedAt: Date;
  downloadUrl?: string;
  previewUrl?: string;
}

/** ecoDMS classification */
export interface EcoDmsClassification {
  id: string;
  name: string;
  color: string;
  documentCount: number;
}

// ============================================
// GembaDocs Types
// ============================================

/** Audit type */
export type AuditType = 'internal' | 'external' | 'certification';

/** Finding severity */
export type FindingSeverity = 'critical' | 'high' | 'medium' | 'low';

/** Audit status */
export type AuditStatus = 'scheduled' | 'in_progress' | 'completed' | 'cancelled';

/** Finding status */
export type FindingStatus = 'open' | 'in_progress' | 'resolved' | 'verified';

/** GembaDocs Audit */
export interface GembaAudit {
  id: string;
  title: string;
  type: AuditType;
  status: AuditStatus;
  department: string;
  auditor: string;
  scheduledDate: Date;
  completedDate?: Date;
  findingsCount: number;
  openFindingsCount: number;
}

/** GembaDocs Finding */
export interface GembaFinding {
  id: string;
  auditId: string;
  title: string;
  description: string;
  severity: FindingSeverity;
  status: FindingStatus;
  department: string;
  responsiblePerson: string;
  dueDate: Date;
  createdAt: Date;
  resolvedAt?: Date;
}

/** GembaDocs Compliance Score */
export interface GembaComplianceScore {
  overall: number;
  byDepartment: Record<string, number>;
  trend: 'up' | 'down' | 'stable';
  lastUpdated: Date;
}
