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

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

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

export const dbCheckerSchemas: CheckerSchemas = {
  config: Type.Object(
    {
      query: Type.Optional(
        Type.String({
          minLength: 1,
        }),
      ),
      url: Type.String({ minLength: 1 }),
    },
    { additionalProperties: false },
  ),
  defaults: Type.Object({}, { additionalProperties: false }),
  expect: Type.Object(
    {
      durationMs: Type.Optional(createRawValueExpectationSchema()),
      result: Type.Optional(createRawContentExpectationsSchema()),
      rowCount: Type.Optional(createRawValueExpectationSchema()),
      rows: Type.Optional(Type.Array(createRawKeyedExpectationsSchema())),
    },
    { additionalProperties: false },
  ),
};
