import * as plugins from '../plugins.js';
import * as data from '../data/index.js';

export type TTelemetrySubscriptionTarget =
  | {
      type: 'serviceLogs';
      serviceName: string;
    }
  | {
      type: 'serviceMetrics';
      serviceName: string;
    }
  | {
      type: 'platformServiceLogs';
      serviceType: data.TPlatformServiceType;
    }
  | {
      type: 'platformServiceMetrics';
      serviceType: data.TPlatformServiceType;
    };

export interface IReq_SubscribeTelemetry extends plugins.typedrequestInterfaces.implementsTR<
  plugins.typedrequestInterfaces.ITypedRequest,
  IReq_SubscribeTelemetry
> {
  method: 'subscribeTelemetry';
  request: {
    identity: data.IIdentity;
    target: TTelemetrySubscriptionTarget;
    subscriptionId?: string;
  };
  response: {
    subscriptionId: string;
    leaseExpiresAt: number;
  };
}

export interface IReq_UnsubscribeTelemetry extends plugins.typedrequestInterfaces.implementsTR<
  plugins.typedrequestInterfaces.ITypedRequest,
  IReq_UnsubscribeTelemetry
> {
  method: 'unsubscribeTelemetry';
  request: {
    identity: data.IIdentity;
    subscriptionId: string;
  };
  response: {
    ok: boolean;
  };
}

export interface IReq_UnsubscribeAllTelemetry extends plugins.typedrequestInterfaces.implementsTR<
  plugins.typedrequestInterfaces.ITypedRequest,
  IReq_UnsubscribeAllTelemetry
> {
  method: 'unsubscribeAllTelemetry';
  request: {
    identity: data.IIdentity;
  };
  response: {
    ok: boolean;
  };
}

export interface IReq_PushTelemetryLog extends plugins.typedrequestInterfaces.implementsTR<
  plugins.typedrequestInterfaces.ITypedRequest,
  IReq_PushTelemetryLog
> {
  method: 'pushTelemetryLog';
  request: {
    target: TTelemetrySubscriptionTarget;
    entry: data.ILogEntry;
  };
  response: {};
}

export interface IReq_PushTelemetryMetric extends plugins.typedrequestInterfaces.implementsTR<
  plugins.typedrequestInterfaces.ITypedRequest,
  IReq_PushTelemetryMetric
> {
  method: 'pushTelemetryMetric';
  request: {
    target: TTelemetrySubscriptionTarget;
    stats: data.IContainerStats;
    timestamp: number;
  };
  response: {};
}
