import { Type, type Static } from "@sinclair/typebox";

const ModelIdSchema = Type.String({ maxLength: 80, pattern: "^[a-z0-9][a-z0-9.-]+$" });

export const BootstrapResponseSchema = Type.Object(
  {
    app_version: Type.String({ maxLength: 40, pattern: "^[0-9]+\\.[0-9]+\\.[0-9]+(?:[-+][A-Za-z0-9.-]+)?$" }),
    dependencies: Type.Array(
      Type.Object(
        {
          service_id: Type.String({ maxLength: 60, pattern: "^[a-z][a-z0-9_-]+$" }),
          status: Type.Union([
            Type.Literal("available"),
            Type.Literal("paused"),
            Type.Literal("degraded"),
            Type.Literal("unavailable"),
          ]),
        },
        { additionalProperties: false },
      ),
    ),
    model_summary: Type.Object(
      {
        config_set_version: Type.Union([Type.Integer({ minimum: 0 }), Type.Null()]),
        configured_default_model_id: Type.Union([ModelIdSchema, Type.Null()]),
        recommended_model_id: Type.Union([ModelIdSchema, Type.Null()]),
        runtime_availability_version: Type.Union([Type.Integer({ minimum: 0 }), Type.Null()]),
      },
      { additionalProperties: false },
    ),
    public_features: Type.Array(
      Type.Object(
        {
          feature_id: Type.String({ maxLength: 80, pattern: "^[a-z][a-z0-9_-]+$" }),
          status: Type.Union([Type.Literal("enabled"), Type.Literal("disabled"), Type.Literal("paused")]),
        },
        { additionalProperties: false },
      ),
    ),
  },
  { additionalProperties: false, $id: "BootstrapResponse" },
);

export type BootstrapResponse = Static<typeof BootstrapResponseSchema>;
