import { Type } from "@sinclair/typebox";

import type { CheckerSchemas } from "../types";

import {
  createRawContentExpectationsSchema,
  createRawValueExpectationSchema,
  sizeSchema,
} from "../../schema/fragments";

export const udpCheckerSchemas: CheckerSchemas = {
  config: Type.Object(
    {
      encoding: Type.Optional(Type.Union([Type.Literal("text"), Type.Literal("hex"), Type.Literal("base64")])),
      host: Type.String({ minLength: 1 }),
      maxResponseBytes: Type.Optional(sizeSchema),
      payload: Type.Optional(Type.String()),
      port: Type.Integer({ maximum: 65535, minimum: 1 }),
      responseEncoding: Type.Optional(Type.Union([Type.Literal("text"), Type.Literal("hex"), Type.Literal("base64")])),
    },
    { additionalProperties: false },
  ),
  defaults: Type.Object(
    {
      encoding: Type.Optional(Type.Union([Type.Literal("text"), Type.Literal("hex"), Type.Literal("base64")])),
      maxResponseBytes: Type.Optional(sizeSchema),
      responseEncoding: Type.Optional(Type.Union([Type.Literal("text"), Type.Literal("hex"), Type.Literal("base64")])),
    },
    { additionalProperties: false },
  ),
  expect: Type.Object(
    {
      durationMs: Type.Optional(createRawValueExpectationSchema()),
      responded: Type.Optional(Type.Boolean()),
      response: Type.Optional(createRawContentExpectationsSchema()),
      responseSize: Type.Optional(createRawValueExpectationSchema()),
      sourceHost: Type.Optional(createRawValueExpectationSchema()),
      sourcePort: Type.Optional(createRawValueExpectationSchema()),
    },
    { additionalProperties: false },
  ),
};
