import { StructJSON } from './modelOfMatterModel';
import { BasicPageParams } from '/@/api/model/baseModel';
import { AlarmStatus } from '/@/views/alarm/log/config/detail.config';
import { DeviceStatusEnum } from '/@/views/rule/dataFlow/cpns/config';
export enum DeviceState {
  INACTIVE = 'INACTIVE',
  ONLINE = 'ONLINE',
  OFFLINE = 'OFFLINE',
}
export enum DeviceTypeEnum {
  GATEWAY = 'GATEWAY',
  DIRECT_CONNECTION = 'DIRECT_CONNECTION',
  SENSOR = 'SENSOR',
}
export type DeviceProfileQueryParam = BasicPageParams & DeviceProfileParam & DeviceId;
export type DeviceQueryParam = BasicPageParams & {
  deviceProfileIds?: string[];
  convertConfigId?: string;
  deviceType?: DeviceTypeEnum;
  deviceState?: DeviceStatusEnum;
  organizationId?: string;
  alarmStatus?: string;
  orderFiled?: string;
  orderType?: string;
  selected?: boolean;
  name?: string;
};
export type DeviceParam = {
  name?: string;
  deviceProfileId?: string;
};
export type DeviceProfileParam = {
  name?: string;
  status?: AlarmStatus;
};
export type DeviceId = {
  id?: string;
};

export interface DeviceModel {
  id: string;
  name: string;
  deviceInfo: any;
  activeTime: string;
  deviceState: DeviceState;
  alarmStatus: number;
  profileId: string;
  label: string;
  lastConnectTime: string;
  deviceType: DeviceTypeEnum;
  organizationId: string;
  customerId?: string;
}

export interface DeviceProfileModel {
  id: string;
  name: string;
  transportType: string;
  createTime: string;
  description: string;
}

export type ChildDeviceParams = BasicPageParams & {
  formId: string;
};

export interface Configuration {
  type: string;
}

export interface TransportPayloadTypeConfiguration {
  transportPayloadType: string;
  deviceTelemetryProtoSchema: string;
  deviceAttributesProtoSchema: string;
  deviceRpcRequestProtoSchema: string;
  deviceRpcResponseProtoSchema: string;
  enableCompatibilityWithJsonPayloadFormat: boolean;
  useJsonPayloadFormatForDefaultDownlinkTopics: boolean;
}

export interface ClientSettings {
  edrxCycle: string;
  pagingTransmissionWindow: string;
  powerMode: string;
  psmActivityTimer: number;

  clientOnlyObserveAfterConnect: string;
  fwUpdateResource: string;
  fwUpdateStrategy: number;
  swUpdateResource: string;
  swUpdateStrategy: number;
}

export interface Bootstrap {
  securityMode: string;
  shortServerId: number;
  bootstrapServerIs: boolean;
  host: string;
  port: number;
  clientHoldOffTime: number;
  serverPublicKey?: any;
  serverCertificate?: any;
  bootstrapServerAccountTimeout: number;
  lifetime: number;
  defaultMinPeriod: number;
  notifIfDisabled: boolean;
  binding: string;
}

export interface Mapping {
  dataType: string;
  key: string;
  oid: string;
}

export interface CommunicationConfigs {
  spec: string;
  mappings: Mapping[];
  queryingFrequencyMs: number;
}

export interface TransportConfiguration {
  type: string;
  deviceTelemetryTopic: string;
  deviceAttributesTopic: string;

  // MQTT
  transportPayloadTypeConfiguration: TransportPayloadTypeConfiguration;

  // COAP
  clientSettings: ClientSettings;
  coapDeviceTypeConfiguration: {
    coapDeviceType: string;
    transportPayloadTypeConfiguration: TransportPayloadTypeConfiguration;
  };

  // LWM2M
  bootstrapServerUpdateEnable: boolean;
  bootstrap: Bootstrap[];
  clientLwM2mSettings: ClientSettings;

  // SNMP
  retries: number;
  timeoutMs: number;
  communicationConfigs: CommunicationConfigs[];

  // TCP
  scriptId: string;
}

export interface ProvisionConfiguration {
  type: string;
  provisionDeviceSecret?: any;
}

export interface ProfileData {
  configuration: Configuration;
  transportConfiguration: TransportConfiguration;
  provisionConfiguration: ProvisionConfiguration;
  alarms?: any;
}

export interface DeviceRecord {
  id: string;
  creator: string;
  createTime: string;
  name: string;
  tenantId: string;
  transportType: string;
  provisionType: string;
  deviceType: string;
  deviceCount: number;
  tbDeviceId: string;
  tbProfileId: string;
  profileData: ProfileData;
  defaultQueueName: string;
  image: string;
  type: string;
  default: boolean;
  defaultRuleChainId: string;
  profileId: string;
  alias?: string;
  brand?: string;
  deviceProfile: {
    default: boolean;
    name: string;
    transportType: string;
  };
}

export interface DeviceModelOfMatterAttrs {
  name: string;
  identifier: string;
  detail: StructJSON;
}

export interface DeviceStateLogModel {
  items: [
    {
      createTime: string;
      creator: string;
      defaultConfig: string;
      description: string;
      deviceName: string;
      deviceProfileName: string;
      deviceType: string;
      enabled: true;
      icon: string;
      id: string;
      name: string;
      organizationName: string;
      remark: string;
      roleIds: [string];
      status: 0;
      tbDeviceId: string;
      tenantExpireTime: string;
      tenantId: string;
      tenantProfileId: string;
      tenantStatus: string;
      updateTime: string;
      updater: string;
    }
  ];
  total: 0;
}
