# Subscribe to Celestial Body Events

Subscribe to events for all celestial bodies in the galaxy

Events related to all types of celestial bodies (planets, satellites, asteroids, comets).

This is a general channel for monitoring the entire galaxy's celestial activity.


Scalar Galaxy Events sends these messages to you.

Address: `celestial-bodies/events`

## Servers

- `wss://galaxy.scalar.com` (Production, wss)
- `ws://localhost:8080` (Development, ws)
- `kafka://kafka.galaxy.scalar.com:9092` (Event Bus, kafka)
- `mqtt://mqtt.galaxy.scalar.com:1883` (Mqtt Bridge, mqtt)

## Authorization

Connecting to `production` takes one of:

- `bearerAuth` (http bearer): JWT Bearer token authentication for WebSocket connections
- `httpApiKey` (httpApiKey in query `api_key`): API key for WebSocket authentication

## Query Parameters

The query of connection URL: `SubscribeToCelestialBodyEventsQuery`

## Messages

### Celestial Body Created Event

A new celestial body has been added to the galaxy

Published when any type of celestial body is created

Content type: `application/json`

Payload: `CelestialBodyCreatedPayload`

Example payload:

```json
{
  "eventId": "evt_1234567906",
  "eventType": "celestial_body.created",
  "timestamp": "2024-01-15T23:00:00Z",
  "celestialBody": {
    "type": "satellite",
    "satellite": {
      "id": 16,
      "name": "Asteroid X-2024",
      "type": "asteroid",
      "diameter": 1.2
    }
  },
  "discovery": {
    "method": "automated_survey",
    "observatory": "Hubble Space Telescope"
  },
  "metadata": {
    "source": "astronomical-survey",
    "surveyId": "survey_20240115"
  }
}
```

### Celestial Body Updated Event

An existing celestial body has been modified

Published when celestial body properties are updated

Content type: `application/json`

Payload: `CelestialBodyUpdatedPayload`

Example payload:

```json
{
  "eventId": "evt_1234567907",
  "eventType": "celestial_body.updated",
  "timestamp": "2024-01-15T23:30:00Z",
  "celestialBody": {
    "type": "satellite",
    "satellite": {
      "id": 15,
      "name": "Deimos II",
      "orbit": {
        "orbitalPeriod": 1.28,
        "distance": 23500
      }
    }
  },
  "changes": [
    {
      "field": "orbit.orbitalPeriod",
      "oldValue": 1.26,
      "newValue": 1.28
    },
    {
      "field": "orbit.distance",
      "oldValue": 23460,
      "newValue": 23500
    }
  ],
  "metadata": {
    "source": "orbital-mechanics",
    "calculationId": "calc_20240115"
  }
}
```

### Orbital Collision Event

Two celestial bodies have collided

Published when orbital collisions occur

Content type: `application/json`

Payload: `OrbitalCollisionPayload`

Example payload:

```json
{
  "eventId": "evt_1234567908",
  "eventType": "orbital.collision",
  "timestamp": "2024-01-16T00:00:00Z",
  "collision": {
    "type": "asteroid_planet",
    "severity": "minor",
    "energy": "1.2e12"
  },
  "objects": [
    {
      "type": "satellite",
      "id": 17,
      "name": "Asteroid Y-2024",
      "mass": 1500000000000
    },
    {
      "type": "planet",
      "id": 4,
      "name": "Mars"
    }
  ],
  "impact": {
    "location": "Valles Marineris",
    "craterSize": 150,
    "atmosphericEffects": "dust_cloud"
  },
  "metadata": {
    "source": "collision-detector",
    "simulationId": "sim_20240116"
  }
}
```

### New Discovery Event

A significant astronomical discovery has been made

Published for major discoveries and breakthroughs

Content type: `application/json`

Payload: `NewDiscoveryPayload`

Example payload:

```json
{
  "eventId": "evt_1234567909",
  "eventType": "discovery.new",
  "timestamp": "2024-01-16T00:30:00Z",
  "discovery": {
    "type": "habitable_planet",
    "significance": "high",
    "description": "Earth-like planet with liquid water detected"
  },
  "celestialBody": {
    "type": "planet",
    "planet": {
      "id": 50,
      "name": "Kepler-442b",
      "type": "super_earth",
      "habitabilityIndex": 0.84,
      "physicalProperties": {
        "mass": 2.36,
        "radius": 1.34,
        "temperature": {
          "average": 233
        }
      }
    }
  },
  "research": {
    "method": "transit_photometry",
    "observatory": "Kepler Space Telescope",
    "paper": "https://arxiv.org/abs/2401.15000"
  },
  "metadata": {
    "source": "research-team",
    "discoveryId": "disc_20240116"
  }
}
```

## Types

```ts
export type SubscribeToCelestialBodyEventsMessage =
  | CelestialBodyCreatedPayload
  | CelestialBodyUpdatedPayload
  | OrbitalCollisionPayload
  | NewDiscoveryPayload;

export interface SubscribeToCelestialBodyEventsQuery {
  /** Filter by celestial body type */
  bodyType?: "planet" | "satellite" | "asteroid" | "comet";

  /** Filter by minimum habitability index */
  minHabitability?: number;
}

export interface CelestialBodyCreatedPayload {
  eventId: string;
  eventType: "celestial_body.created";
  timestamp: string;
  celestialBody: CelestialBody;
  discovery?: {
    method?: "telescope_observation" | "space_probe" | "mathematical_prediction" | "collision_remnant";
    observatory?: string;
  };
  metadata?: EventMetadata;
}

export interface CelestialBodyUpdatedPayload {
  eventId: string;
  eventType: "celestial_body.updated";
  timestamp: string;
  celestialBody: CelestialBody;
  changes: FieldChange[];
  metadata?: EventMetadata;
}

export interface OrbitalCollisionPayload {
  eventId: string;
  eventType: "orbital.collision";
  timestamp: string;
  collision: {
    type: "asteroid_planet" | "planet_planet" | "satellite_planet" | "asteroid_asteroid";
    severity: "minor" | "moderate" | "major" | "catastrophic";

    /** Energy released in joules (scientific notation) */
    energy: string;
  };
  objects: {
    type?: "planet" | "satellite";
    id?: number;
    name?: string;

    /** Mass in kilograms */
    mass?: number;
  }[];
  impact?: {
    location?: string;

    /** Crater size in meters */
    craterSize?: number;
    atmosphericEffects?: "none" | "dust_cloud" | "atmospheric_heating" | "atmospheric_loss";
  };
  metadata?: EventMetadata;
}

export interface NewDiscoveryPayload {
  eventId: string;
  eventType: "discovery.new";
  timestamp: string;
  discovery: {
    type: "habitable_planet" | "new_element" | "alien_life" | "wormhole" | "black_hole";
    significance: "low" | "medium" | "high" | "revolutionary";
    description: string;
  };
  celestialBody: CelestialBody;
  research?: {
    method?: string;
    observatory?: string;
    paper?: string;
  };
  metadata?: EventMetadata;
}

/** A celestial body which can be either a planet or a satellite */
export interface CelestialBody {
  /** Type of celestial body */
  type: "planet" | "satellite";

  /** Planet data (when type is 'planet') */
  planet?: Planet;

  /** Satellite data (when type is 'satellite') */
  satellite?: Satellite;
}

export interface EventMetadata {
  /** Source system that generated the event */
  source?: string;

  /** ID of the user who triggered the event (if applicable) */
  userId?: number;

  /** ID of the request that triggered the event */
  requestId?: string;

  /** Correlation ID for tracing related events */
  correlationId?: string;

  /** Event severity level */
  severity?: "info" | "warning" | "error" | "critical";
}

export interface FieldChange {
  /** Name of the field that changed */
  field: string;

  /** Previous value of the field */
  oldValue: unknown;

  /** New value of the field */
  newValue: unknown;
}

/** A planet in the Scalar Galaxy */
export interface Planet {
  readonly id: number;
  name: string;
  description?: string;
  type?: "terrestrial" | "gas_giant" | "ice_giant" | "dwarf" | "super_earth";
  habitabilityIndex?: number;
  physicalProperties?: {
    mass?: number;
    radius?: number;
    gravity?: number;
    temperature?: {
      min?: number;
      max?: number;
      average?: number;
    };
  };
  atmosphere?: {
    compound?: string;
    percentage?: number;
  }[];
  discoveredAt?: string;
  image?: string;
  satellites?: Satellite[];
  creator?: User;
  tags?: string[];
  readonly lastUpdated?: string;
}

/** Every satellite in the Scalar Galaxy */
export interface Satellite {
  readonly id?: number;
  name: string;
  description?: string;
  diameter?: number;
  type?: "moon" | "asteroid" | "comet";
  orbit?: {
    planet?: Planet;
    orbitalPeriod?: number;
    distance?: number;
  };
}

/** A user */
export interface User {
  readonly id?: number;
  name?: string;
}
```
