// Zoho Projects API Types
export interface ZohoUser {
  zuid: number;
  zpuid: string;
  name: string;
  email: string;
  first_name: string;
  last_name: string;
  full_name: string;
}

export interface ZohoProjectStatus {
  id: string;
  name: string;
  color: string;
  color_hexcode: string;
  is_closed_type: boolean;
}

export interface ZohoProjectLayout {
  id: string;
  name: string;
  is_default: boolean;
  type: string;
}

export interface ZohoProjectGroup {
  id: string;
  name: string;
  type: string;
}

export interface ZohoBudgetInfo {
  tracking_method: string;
}

export interface ZohoTaskCounts {
  open_count: number;
  closed_count: number;
}

export interface ZohoIssueCounts {
  open_count: number;
  closed_count: number;
}

export interface ZohoMilestoneCounts {
  open_count: number;
  closed_count: number;
}

export interface ZohoPortal {
  id: string;
  name: string;
  org_name: string;
  portal_url: string;
}

export interface ZohoProject {
  id: string;
  key: string;
  name: string;
  project_type: string;
  owner: ZohoUser;
  is_public_project: boolean;
  start_date: string;
  end_date: string;
  is_strict_project: boolean;
  created_time: string;
  created_by: ZohoUser;
  modified_time: string;
  updated_by: ZohoUser;
  status: ZohoProjectStatus;
  layout: ZohoProjectLayout;
  business_hours_id: string;
  is_rollup_project: boolean;
  budget_info: ZohoBudgetInfo;
  project_group: ZohoProjectGroup;
  percent_complete: number;
  tasks: ZohoTaskCounts;
  issues: ZohoIssueCounts;
  milestones: ZohoMilestoneCounts;
  is_completed: boolean;
  portal: ZohoPortal;
}

export interface ZohoTaskMilestone {
  id: string;
  name: string;
}

export interface ZohoTaskList {
  id: string;
  name: string;
}

export interface ZohoTaskProject {
  id: string;
  name: string;
}

export interface ZohoTaskStatus {
  id: string;
  name: string;
  color: string;
  color_hexcode: string;
  is_closed_type: boolean;
}

export interface ZohoTaskOwner {
  zuid: number;
  zpuid: string;
  name: string;
  email: string;
  first_name: string;
  last_name: string;
  work_values: string;
}

export interface ZohoTaskOwnersAndWork {
  work_type: string;
  total_work: string;
  unit: string;
  copy_task_duration: boolean;
  owners: ZohoTaskOwner[];
  refresh_business_hours: boolean;
}

export interface ZohoTaskDuration {
  value: string;
  type: string;
}

export interface ZohoTaskSequence {
  sequence: number;
}

export interface ZohoTaskLogHours {
  billable_hours: string;
  non_billable_hours: string;
  total_hours: string;
}

export interface ZohoTaskAssociationInfo {
  has_reminder: boolean;
  has_recurrence: boolean;
  has_comments: boolean;
  has_attachments: boolean;
  has_forums: boolean;
  has_subtasks: boolean;
}

// Issue types
export interface ZohoIssueProject {
  id: string;
  name: string;
}

export interface ZohoIssueAssignee {
  zuid: number;
  zpuid: string;
  name: string;
  email: string;
  first_name: string;
  last_name: string;
}

export interface ZohoIssueStatus {
  id: string;
  name: string;
  color: string;
  color_hexcode: string;
  is_closed_type: boolean;
}

export interface ZohoIssueMilestone {
  id: string;
  value: string;
}

export interface ZohoIssueSeverity {
  id: string;
  value: string;
}

export interface ZohoIssueClassification {
  id: string;
  value: string;
}

export interface ZohoIssueReproducible {
  id: string;
  value: string;
}

export interface ZohoIssueModule {
  id: string;
  value: string;
}

export interface ZohoIssue {
  id: string;
  prefix: string;
  name: string;
  project: ZohoIssueProject;
  flag: string;
  created_time: string;
  created_by: ZohoUser;
  status: ZohoIssueStatus;
  assignee: ZohoIssueAssignee;
  last_updated_time: string;
  release_milestone: ZohoIssueMilestone;
  affected_milestone: ZohoIssueMilestone;
  severity: ZohoIssueSeverity;
  classification: ZohoIssueClassification;
  is_it_reproducible: ZohoIssueReproducible;
  module: ZohoIssueModule;
}

// Phase types
export interface ZohoPhaseOwner {
  zpuid: string;
  last_name: string;
  is_client_user: boolean;
  first_name: string;
  email: string;
  zuid: number;
}

export interface ZohoPhaseProject {
  name: string;
  id: string;
}

export interface ZohoPhaseStatus {
  color_hexcode: string;
  name: string;
  id: string;
  is_closed: boolean;
}

export interface ZohoPhaseBudgetInfo {
  is_workfield_removed: boolean;
}

export interface ZohoPhase {
  id: string;
  name: string;
  project: ZohoPhaseProject;
  owner: ZohoPhaseOwner;
  start_date: string;
  end_date: string;
  created_time: string;
  last_modified_time: string;
  flag: string;
  status_type: string;
  status: ZohoPhaseStatus;
  budget_info: ZohoPhaseBudgetInfo;
}

export interface ZohoTask {
  id: string;
  prefix: string;
  name: string;
  description: string;
  project: ZohoTaskProject;
  milestone: ZohoTaskMilestone;
  tasklist: ZohoTaskList;
  status: ZohoTaskStatus;
  priority: string;
  owners_and_work: ZohoTaskOwnersAndWork;
  start_date: string;
  end_date: string;
  completed_on?: string;
  duration: ZohoTaskDuration;
  completion_percentage: number;
  sequence: ZohoTaskSequence;
  depth: number;
  created_time: string;
  last_modified_time: string;
  is_completed: boolean;
  created_via: string;
  created_by: ZohoUser;
  billing_type: string;
  log_hours: ZohoTaskLogHours;
  association_info: ZohoTaskAssociationInfo;
}

export interface ZohoApiInfo {
  count: number;
  moreRecords: boolean;
  page: number;
  pageCount?: number;
}

export interface ZohoProjectsApiResponse {
  status: string;
  message: string;
  data: {
    data: ZohoProject[];
    info: ZohoApiInfo;
  };
  timestamp: string;
}

export interface ZohoTasksApiResponse {
  status: string;
  message: string;
  data: {
    data: ZohoTask[];
    info: ZohoApiInfo;
  };
  timestamp: string;
}

export interface ZohoIssuesApiResponse {
  status: string;
  message: string;
  data: {
    data: ZohoIssue[];
    info: ZohoApiInfo;
  };
  timestamp: string;
}

export interface ZohoPhasesApiResponse {
  status: string;
  message: string;
  data: {
    data: ZohoPhase[];
    info: ZohoApiInfo;
  };
  timestamp: string;
}

// Dashboard specific types
export interface ZohoProjectsDashboardStats {
  totalProjects: number;
  activeProjects: number;
  completedProjects: number;
  totalTasks: number;
  openTasks: number;
  closedTasks: number;
  totalMilestones: number;
  openMilestones: number;
  closedMilestones: number;
  totalIssues: number;
  openIssues: number;
  closedIssues: number;
  totalPhases: number;
  activePhases: number;
  completedPhases: number;
  averageCompletionRate: number;
  totalTeamMembers: number;
  totalWorkHours: number;
  billableHours: number;
  nonBillableHours: number;
  averageTaskCompletion: number;
  highPriorityTasks: number;
  overdueTasks: number;
  averagePhaseCompletion: number;
}

export interface ZohoProjectsFilters {
  status?: string;
  projectType?: string;
  owner?: string;
  dateRange?: {
    start: string;
    end: string;
  };
}

export interface ZohoProjectsState {
  projects: ZohoProject[];
  tasks: ZohoTask[];
  issues: ZohoIssue[];
  phases: ZohoPhase[];
  loading: {
    projects: boolean;
    tasks: boolean;
    issues: boolean;
    phases: boolean;
  };
  error: {
    projects: string | null;
    tasks: string | null;
    issues: string | null;
    phases: string | null;
  };
  pagination: {
    projects: ZohoApiInfo;
    tasks: ZohoApiInfo;
    issues: ZohoApiInfo;
    phases: ZohoApiInfo;
  };
  lastUpdated: string | null;
  filters: ZohoProjectsFilters;
}
