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

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

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

export const tcpCheckerSchemas: CheckerSchemas = {
  config: Type.Object(
    {
      bannerReadTimeout: Type.Optional(Type.Number({ minimum: 0 })),
      host: Type.String({ minLength: 1 }),
      maxBannerBytes: Type.Optional(sizeSchema),
      port: Type.Integer({ maximum: 65535, minimum: 1 }),
      readBanner: Type.Optional(Type.Boolean()),
    },
    { additionalProperties: false },
  ),
  defaults: Type.Object(
    {
      bannerReadTimeout: Type.Optional(Type.Number({ minimum: 0 })),
      maxBannerBytes: Type.Optional(sizeSchema),
    },
    { additionalProperties: false },
  ),
  expect: Type.Object(
    {
      banner: Type.Optional(createRawContentExpectationsSchema()),
      connected: Type.Optional(Type.Boolean()),
      durationMs: Type.Optional(createRawValueExpectationSchema()),
    },
    { additionalProperties: false },
  ),
};
