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

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

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

export const commandCheckerSchemas: CheckerSchemas = {
  config: Type.Object(
    {
      args: Type.Optional(Type.Array(Type.String())),
      cwd: Type.Optional(Type.String()),
      env: Type.Optional(stringMapSchema),
      exec: Type.String({ minLength: 1 }),
      maxOutputBytes: Type.Optional(sizeSchema),
    },
    { additionalProperties: false },
  ),
  defaults: Type.Object(
    {
      cwd: Type.Optional(Type.String()),
      maxOutputBytes: Type.Optional(sizeSchema),
    },
    { additionalProperties: false },
  ),
  expect: Type.Object(
    {
      durationMs: Type.Optional(createRawValueExpectationSchema()),
      exitCode: Type.Optional(Type.Array(Type.Integer())),
      stderr: Type.Optional(createRawContentExpectationsSchema()),
      stdout: Type.Optional(createRawContentExpectationsSchema()),
    },
    { additionalProperties: false },
  ),
};
