export type UserRole = 'sales' | 'dispatch' | 'construction'
export type UserStatus = 'active' | 'inactive'

export interface User {
  id: string
  name: string
  phone: string
  avatar?: string
  role: UserRole
  department?: string
  position?: string
  employeeNo?: string
  email?: string
  hireDate?: string
  team?: string
  status: UserStatus
}

export type ProjectType = '包年' | '单次' | '季度' | '月付'
export type ProjectStatus = 'pending' | 'confirmed' | 'processing' | 'completed' | 'cancelled'

export interface Contact {
  name: string
  phone: string
  role: string
}

export interface ServicePoint {
  id: string
  name: string
  location: string
  address?: string
  serviceType: string
  contactName?: string
  contactPhone?: string
}

export interface Project {
  id: string
  name: string
  type: ProjectType
  status: ProjectStatus
  customerName: string
  customerPhone: string
  address: string
  province?: string
  city?: string
  district?: string
  contacts: Contact[]
  servicePoints: ServicePoint[]
  contractAmount?: number
  contractStartDate?: string
  contractEndDate?: string
  serviceCycle?: string
  remark?: string
  location?: { lat: number; lng: number }
  createTime: string
  updateTime: string
}

/** 后端分页结果（PageResult） */
export interface PageResult<T> {
  rows: T[]
  total: number
  current: number
  size: number
  pages: number
}

/** 客户状态：1 合作中 / 0 已停用 / 2 潜在客户（后端硬编码） */
export type CustomerStatus = 0 | 1 | 2

export interface Customer {
  id: number | string
  customerName: string
  contactName?: string
  phone?: string
  address?: string
  province?: string
  city?: string
  district?: string
  street?: string
  detailAddress?: string
  latitude?: string
  longitude?: string
  status: CustomerStatus
  remark?: string
  createTime?: string
  updateTime?: string
}

export type ContractStatus = 'draft' | 'pending' | 'active' | 'expired' | 'terminated'
export type PaymentMethod = 'lump_sum' | 'installment'

export interface Contract {
  id: number | string
  contractNo: string
  customerId: number | string
  customerName?: string
  projectId?: number | string
  contractAmount: number
  paymentMethod: PaymentMethod
  signDate?: string
  servicePeriod?: string
  status: ContractStatus
  remark?: string
  createTime?: string
  updateTime?: string
}

export type TaskType = 'regular' | 'emergency'
export type TaskStatus =
  | 'pending'
  | 'confirmed'
  | 'scheduled'
  | 'departed'
  | 'arrived'
  | 'constructing'
  | 'inspecting'
  | 'completed'
  | 'cancelled'
  | 'rejected'
export type UrgentLevel = 'high' | 'normal'

export interface TimelineRecord {
  time: string
  action: string
  operator: string
  role: UserRole
}

export interface Task {
  id: string
  projectId: string
  projectName: string
  coopType?: string
  type: TaskType
  status: TaskStatus
  urgent: UrgentLevel
  serviceType?: string
  facilityType?: string
  serviceMode?: string
  faultLocation?: string
  faultDesc?: string
  address?: string
  geoLocation?: string
  vehicle?: string
  vehicleNo?: string
  team?: string
  assignee?: string
  staffName?: string
  applicant?: string
  applicantPhone?: string
  applyTime?: string
  rejectReason?: string
  acceptType?: string
  acceptRequirement?: string
  estimatedQuantity?: string
  estimatedHours?: string
  constructionHelp?: string
  waterSource?: string
  septicTank?: string
  previousConstruction?: string
  customerName?: string
  customerPhone?: string
  partyAContacts?: { name: string; phone: string }[]
  contacts?: { name: string; phone: string; role?: string }[]
  scheduledDate?: string
  scheduleDate?: string
  scheduleTime?: string
  serviceDate?: string
  serviceTime?: string
  departTime?: string
  arriveTime?: string
  constructTime?: string
  completeTime?: string
  cleanTime?: string
  inspectTime?: string
  createTime: string
  timeline: TimelineRecord[]
  location?: { lat: number; lng: number }
  mediaList?: { type: 'image' | 'video'; url: string }[]
}

export type ScheduleStatus = 'scheduled' | 'completed' | 'cancelled'

export interface Schedule {
  id: string
  date: string
  team: string
  taskId: string
  taskName: string
  status: ScheduleStatus
}

export type VehicleStatus = 'available' | 'in_use' | 'maintenance'

export interface Vehicle {
  id: string
  plateNumber: string
  type: string
  status: VehicleStatus
  driver?: string
  driverPhone?: string
  size?: string
  loadCapacity?: string
  capacity?: string
  purchaseDate?: string
  mileage?: number
}

export type PersonnelStatus = 'idle' | 'working' | 'rest' | 'standby'

export interface Personnel {
  id: string
  name: string
  phone: string
  team: string
  status: PersonnelStatus
  position?: string
  skillLevel?: string
  qualifications?: string[]
  workYears?: number
}

export type NotificationType = 'system' | 'task' | 'audit'

export interface Notification {
  id: string
  title: string
  content: string
  type: NotificationType
  read: boolean
  createTime: string
}

export interface Knowledge {
  id: string
  title: string
  summary: string
  content: string
  category: string
  createTime: string
}

export interface FAQ {
  id: string
  question: string
  answer: string
  category: string
}

export interface NavItem {
  path: string
  icon: string
  activeIcon?: string
  text?: string
  name?: string
}

export interface ToastOptions {
  title: string
  icon?: 'success' | 'loading' | 'none' | 'error'
  duration?: number
  mask?: boolean
}

export interface ModalOptions {
  title?: string
  content: string
  showCancel?: boolean
  cancelText?: string
  confirmText?: string
  success?: (res: { confirm: boolean; cancel: boolean }) => void
}
