import type { TabPaneProps, TreeOption } from 'naive-ui';
import type { VimpChannel, VimpStation } from '../apis/model';

export type SiteType = 'station' | 'parking' | 'occ' | 'train';
export type CodeLines = Record<string, { name: string; color: string }>;
export type CodeSites = Record<string, { name: string; type: SiteType }>;
export type CodeArea = { code: string; name: string; subs: { code: string; name: string }[] };

export interface CountStats {
  online: number;
  offline: number;
  total: number;
}

// ==========================================
// 摄像机树相关类型
// ==========================================
export interface CameraNodeOption extends TreeOption {
  camera: VimpChannel;
  type: string;
  site: VimpStation;
}

export interface CameraSubAreaNodeOption extends TreeOption {
  children?: CameraNodeOption[];
  stats: CountStats;
  site: VimpStation;
}

export interface CameraAreaNodeOption extends TreeOption {
  children?: CameraSubAreaNodeOption[];
  stats: CountStats;
  site: VimpStation;
}

export interface CameraSiteNodeOption extends TreeOption {
  children?: CameraAreaNodeOption[];
  stats: CountStats;
  online: boolean;
}

export function isCameraSiteNode(option: TreeOption): option is CameraSiteNodeOption {
  return 'online' in option && !('camera' in option);
}

export function isCameraAreaNode(option: TreeOption): option is CameraAreaNodeOption | CameraSubAreaNodeOption {
  return 'site' in option && !('camera' in option) && !('online' in option);
}

export function isCameraNode(option: TreeOption): option is CameraNodeOption {
  return 'camera' in option && 'site' in option;
}

export interface CameraLineTabPane extends TabPaneProps {
  lineCode: string;
  lineName: string;
  cameraTree: CameraSiteNodeOption[];
}

// ==========================================
// 警报器树相关类型
// ==========================================
export interface AlarmNodeOption extends TreeOption {
  alarm: VimpChannel;
  type: string;
  site: VimpStation;
}

export interface AlarmSubAreaNodeOption extends TreeOption {
  children?: AlarmNodeOption[];
  stats: CountStats;
  site: VimpStation;
}

export interface AlarmAreaNodeOption extends TreeOption {
  children?: AlarmSubAreaNodeOption[];
  stats: CountStats;
  site: VimpStation;
}

export interface AlarmSiteNodeOption extends TreeOption {
  children?: AlarmAreaNodeOption[];
  stats: CountStats;
  online: boolean;
}

export function isAlarmSiteNode(option: TreeOption): option is AlarmSiteNodeOption {
  return 'online' in option && !('alarm' in option);
}

export function isAlarmAreaNode(option: TreeOption): option is AlarmAreaNodeOption | AlarmSubAreaNodeOption {
  return 'site' in option && !('alarm' in option) && !('online' in option);
}

export function isAlarmNode(option: TreeOption): option is AlarmNodeOption {
  return 'alarm' in option && 'site' in option;
}

export interface AlarmLineTabPane extends TabPaneProps {
  lineCode: string;
  lineName: string;
  alarmTree: AlarmSiteNodeOption[];
}
