import React from 'react';
import { LegacyButtonType } from 'antd/lib/button/button';

export type TypeNameDescriptionModel = {
  id: number;
  name: string;
  description: string;
};

export interface TypeTags {
  name: string;
  description: string;
  id: number;
  devices?: TypeDevicesGroupItem[] | [];
}

export type TypeTagCreate = Omit<TypeTags, 'id' | 'devices'>;

export type TypeCardSize = 'small' | 'large' | undefined;

export enum EIncidentStatusLabel {
  Not_Assigned = 'notAssigned',
  Assigned = 'assigned',
  Delayed = 'delayed',
  Resolved = 'resolved',
  False_Alarm = 'falseAlarm',
}

export type TUseColumns = {
  disabled?: boolean;
  title: string;
  dataIndex: string;
  key: string;
  hidden?: boolean;
  checked?: boolean;
  width?: number | string;
  align?: string;
  sortOrder?: boolean | string;
  sorter?: boolean;
  render?: (text: any) => JSX.Element | Element | string;
};

export interface AssetsRecord {
  id: string;
  name: string;
  asset_type: string;
  status: number;
  ip: string;
  updated: string;
  incidents: number;
  vulnerabilities: number;
}

export type TypeAssetGroup = {
  id: number;
  name: string;
  description: string;
  collapsed: boolean;
};

export type TypeAssetOS = TypeNameDescriptionModel;

export type TypeAssetManufacturer = TypeNameDescriptionModel;

export enum EnumAssetType {
  User = 'user',
  ArmaIndustrialFirewall = 'arma_industrial_firewall',
  PLC = 'plc',
  PC = 'pc',
  Server = 'server',
  NetworkDevice = 'network_device',
}

export enum EnumAssetStatus {
  Forbidden = 0,
  Allowed = 1,
}

export interface AccountRecord {
  comment: string;
  expire_date: string;
  timezone: string;
  modified: string;
  user: {
    email: string;
    first_name: string;
    username: string;
    password: string;
  };
}
export interface AccountRecordFromPost {
  comment?: string;
  expire_date?: string;
  timezone?: string;
  user?: {
    email?: string;
    first_name?: string;
    username?: string;
    password?: string;
  };
}
export interface AccountRecordResponse {
  comment: string;
  expire_date: string;
  modified: string;
  timezone: string;
  user: {
    email: string;
    first_name: string;
    id: string;
    is_active: boolean;
    username: string;
    password: string;
  };
}

export type TypeAccount = {
  comment: string;
  expire_date: string | null;
  modified: string;
  timezone: string;
  user: {
    email: string;
    first_name: string;
    id: number;
    is_active: boolean;
    username: string;
    password: string;
    old_password: string;
  };
};

export type TypeAccountForBackend = {
  comment: string;
  expire_date: string | null;
  modified: string;
  timezone: string;
  user: {
    email: string;
    first_name: string;
    id: number;
    is_active: boolean;
    username: string;
    password?: string;
    old_password?: string;
  };
};

export interface IncidentsRecord {
  assigned_to: any;
  category: any;
  created: string;
  event_count: number;
  events: any[];
  importance: number;
  incident_id: string;
  status: number;
  timestamp: string;
  title: string;
  updated: string;
  user_friendly_id: number;
}

export type TypeIncidentCategory = TypeNameDescriptionModel;

export type TypeIncidentEffect = TypeNameDescriptionModel;

export type TypeIncidentRecommendation = TypeNameDescriptionModel;

export interface EventsJournalRecord {
  _index: string;
  _type: string;
  _id: string;
  _score: null;
  event_id: string;
  _source: {
    device_version: string;
    sign_subcategory: string;
    device_product: string;
    event_src_msg: string;
    device_action: string;
    destination_port: 0;
    destination_user: string;
    event_count: 42;
    event_severity: 5;
    aggregated_id: string;
    Index: string;
    type: string;
    event_timestamp: string;
    source_ip: string;
    sign_name: string;
    destination_ip: string;
    source_port: 0;
    event_first: string;
    source_user: string;
    source_host: string;
    Updated: 0;
    sign_id: string;
    event_protocol: string;
    destination_host: string;
    source_mac: string;
    '@created': string;
    rule_tags: null | string[];
    event_last: string;
    '@timestamp': string;
    event_id: string;
    sign_category: string;
    event_hash: string;
    celery_done: boolean;
    device_vendor: string;
  };
}
export interface CorrelationRulesRecord {
  id: number;
  name: string;
  description: string;
  group: CorrelationRulesGroupRecord | null;
  multi: boolean;
  type: CorrelationRulesType;
  status: boolean;
  archived: boolean;
  depth: string;
  created: string;
  updated: string;
  rule_json: CorrelationRulesContentRecord;
  actions_json: Array<CorrelationRulesActionRecord>;
  rev: number;
  sid: number;
  is_active: boolean;
}
export interface CorrelationRulesRecordForBackend
  extends Omit<CorrelationRulesRecord, 'group'> {
  group: number | null;
}
export interface CorrelationRulesGroupRecord {
  id: number;
  name: string;
  description: string;
}
export enum CorrelationRulesType {
  System = 0,
  User = 1,
}
export type CorrelationRulesActionRecord =
  | {
      type: 'bash';
      body: string;
    }
  | {
      type: 'http';
      url: string;
      content_type: 'text/plain' | 'application/json';
      template: string;
    }
  | {
      type: 'syslog';
      host: string;
      port: number;
      protocol: 'tcp' | 'udp';
      name: string;
      template: string;
    }
  | {
      type: 'incident';
      title: string;
      category: TypeIncidentCategory | null;
      importance: string;
      assigned_to: string;
      description: string;
      comment: string;
      close_recommendations: Array<string>;
      effects: Array<string>;
    }
  | {
      type: 'exec';
      path: string;
      args: string;
      env: string;
      cwd: string;
    }
  | {
      type: 'asset';
      name: string;
      asset_type: EnumAssetType | null;
      group: string | null;
      description: string;
      manufacturer: string | null;
      model: string;
      os: string | null;
      ip: string;
      ports: string;
    }
  | {
      type: 'firewall';
      armaif: string | null;
      sensor: {
        ip: string;
        scheme: 'https';
        key: string;
        secret: string;
      };
      enabled: boolean;
      quick: boolean;
      log: boolean;
      interface: Array<string>;
      direction: string;
      sequence: string;
      action: string;
      ipprotocol: string;
      protocol: string;
      source_net: string;
      source_port: string;
      source_not: boolean;
      destination_net: string;
      destination_port: string;
      destination_not: boolean;
      description: string;
      gateway: string;
    };
export type CorrelationRulesContentRecord = {
  field: string;
  operands: string;
  type: string;
};
export interface DevicesRecord {
  comment: string;
  id: number;
  ip: string;
  key: string;
  link_addr: string;
  name: string;
  scheme: string;
  secret: string;
  sensor_info: number;
  type: string;
}
export interface StorageRecord {
  created: string;
  description: string;
  file: string;
  format: string;
  free_date: string | null;
  id: number;
  last_access: string;
  size: number;
  type: number;
  user: number;
}
export interface EndpointRecord {
  id: number;
  title: string;
  status: boolean;
  updated: string;
}

export interface IncidentsList {
  data: Array<IncidentsRecord>;
}
export interface IAssetsTable {
  selectedRowKeys: any[];
  loading: boolean;
  pagination: {
    current: string;
    pageSize: number;
    total: number;
  };
}

export interface ConfirmModal {
  title: string | React.ReactNode;
  okType: LegacyButtonType;
  okText?: string;
  cancelText?: string;
  action: () => void;
}

export interface IReadManyResponse<T = any> {
  count: number;
  next: string | null;
  previous: string | null;
  results: Array<T>;
}

export interface IRotationSettings {
  rotation_type: number;
  size_rotation: number;
  task: null;
}
export interface ISettingsAuth {
  login_attempts_limit: number;
  login_block_timeout: string;
}
export interface ISettingsTls {
  enabled: boolean;
  certificate: string;
  key: string;
}
export interface IDevicesList {
  id: number;
  key: number;
  name: string;
  description: string;
  type: 'firewall' | 'endpoint';
  ip: string;
  port: number;
  status: { status: string };
  updated: string;
}
export interface ITagsList {
  description: string;
  devices: { id: number; name: string }[];
  id: number;
  name: string;
}
export interface IDevicePatch {
  name: string;
  description: string;
  ip: string;
  port: number;
  adjust_datetime?: number;
  key?: string;
  secret?: string;
  comment: string;
  group: number;
  updated?: string;
  status: any;
  whitelist_enabled: boolean;
  whitelist_admin: boolean;
  white_list_paths: any;
  integrity_control_enabled: boolean;
  integrity_control_timeout: number;
  scan_paths: any;
  antivirus_enabled: boolean;
  antivirus_remove_infected_files: boolean;
  antivirus_start_scan: boolean;
  antivirus_paths: any;
  device_control_enabled: boolean;
  prohibit_cd_access: boolean;
  usb_control_enabled: boolean;
  event_rotation_period: number;
  event_rotation_size: number;
  event_rotation_time: string;
  event_rotation_type: number;
}

export type TypeEndpointDevice = {
  id: number;
  name: string;
  description: string;
  type: string;
  ip: string;
  port: number;
  adjust_datetime: number;
  updated: string;
  status: { status: 'online' | 'offline' | 'unauthorized' | 'config_errors' };
  whitelist_enabled: boolean;
  whitelist_admin: boolean;
  white_list_paths: string[];
  integrity_control_enabled: boolean;
  integrity_control_timeout: number;
  scan_paths: string[];
  antivirus_enabled: boolean;
  antivirus_remove_infected_files: boolean;
  antivirus_start_scan: boolean;
  antivirus_paths: string[];
  device_control_enabled: boolean;
  prohibit_cd_access: boolean;
  usb_control_enabled: boolean;
  group: { id: number; name: string } | null;
  event_rotation_period: number;
  event_rotation_size: number;
  event_rotation_time: string;
  event_rotation_type: number;
};

export type TypeFirewallDevice = {
  id: number;
  name: string;
  description: string;
  type: string;
  ip: string;
  port: number;
  adjust_datetime: number;
  key: string;
  secret: string;
  comment: string;
  website: string;
  version: string;
  group: { id: number; name: string } | null;
  status: { status: 'online' | 'offline' | 'unauthorized' | 'config_errors' };
  remote_name: string;
  identification_number: string;
  hash_number: string;
  flavour: string;
  email: string;
  copyright_years: string;
  copyright_url: string;
  copyright_owner: string;
  architecture: string;
  abi: string;
  updated: string;
};

export type TypeFirewallStatus = {
  status: 'online' | 'offline';
};

export type TypeFirewallFieldValues = {
  rule: {
    enabled: TypeFirewallFieldValueBoolean;
    sequence: TypeFirewallFieldValueBoolean;
    action: TypeFirewallFieldValueOptions;
    quick: TypeFirewallFieldValueBoolean;
    interface: TypeFirewallFieldValueOptions;
    direction: TypeFirewallFieldValueOptions;
    ipprotocol: TypeFirewallFieldValueOptions;
    protocol: TypeFirewallFieldValueOptions;
    source_net: string | 'any';
    source_not: TypeFirewallFieldValueBoolean;
    source_port: string;
    destination_net: string | 'any';
    destination_not: TypeFirewallFieldValueBoolean;
    destination_port: string;
    gateway: TypeFirewallFieldValueOptions;
    log: TypeFirewallFieldValueBoolean;
    description: string;
  };
};

export type TypeFirewallFieldValueOptions = {
  [name: string]: {
    value: string;
    selected: 0 | 1;
  };
};

export type TypeFirewallFieldValueBoolean = '0' | '1';

type TypeDevicesGroupItem = {
  id: number;
  name: string;
};

export interface InterfaceWithIdAndName {
  id: number | string;
  name: string;
}

export interface InterfaceWithIdNameDescription {
  id: number;
  name: string;
  description: string;
}

export type TypeLicense = {
  license: {
    customer: string;
    product: string;
    type: string;
    evaluationStart: string;
    evaluationEnd: string;
    features: Array<string>;
    options: Record<string, string | number | boolean>;
  };
  features: Array<{
    name: string;
    description: string;
  }>;
  options: Array<{
    name: string;
    value: string | number | boolean;
    description: string;
  }>;
};

export type TypeCurrentUser = {
  id: number;
  username: string;
  first_name: string;
  is_active: boolean;
  email: string;
};
