import {
  IAddtionalCloud,
  IAddtionalDot,
  IAddtionalEdge,
  IAddtionalElements,
  IAddtionalTriage,
  getCloudForm,
  getDotForm,
  getEdgeForm,
  getTriageForm,
} from "./additional";
import {  IElementType } from "./element";
import {
 IJointType,
  jointValidatorFileds,
} from "./joint";

export const getFormDefinition = (
  type: string,
  data: IElementType | IAddtionalElements,
) => {
  if (type === "dot") {
    return getDotForm(data as IAddtionalDot);
  } else if (type === "triage") {
    return getTriageForm(data as IAddtionalTriage);
  } else if (type === "edge") {
    return getEdgeForm(data as IAddtionalEdge);
  } else if (type === "cloud") {
    return getCloudForm(data as IAddtionalCloud);
  }
};

export const jointValidator = (data: IElementType): boolean => {
  let isValid = true;

  for (const field of jointValidatorFileds) {
    const validationValue = data[field as keyof typeof data];

    if (typeof validationValue === "string" && validationValue.length === 0) {
      isValid = false;
    } else if (
      typeof validationValue === "number" &&
      (validationValue === 0 || validationValue === undefined)
    ) {
      isValid = false;
    }
  }
  return isValid;
};
