import * as Yup from "yup";
import dayjs from "dayjs";
import { Payments } from "../../../../../../enums/Validation";

export const getInitialValues = (objectToEdit: any): any => {
  console.log(objectToEdit, "objectToEdit");

  return {
    id: objectToEdit?.id ?? null,
    registration_record_id:
      objectToEdit?.registration_record?.id ??
      objectToEdit?.registration_record_id ??
      null,
    type: objectToEdit?.type ?? null,
    value: objectToEdit?.value ?? null,
    details: objectToEdit?.details ?? null,
    receipt_number: objectToEdit?.receipt_number ?? null,
    date: objectToEdit?.date
      ? dayjs(objectToEdit?.date, "YYYY/MM/DD")
      : dayjs(Date()),
  };
};

export const getValidationSchema = () => {
  // validate input
  return Yup.object().shape({
    type: Yup.string().required("validation.type_required"),
    value: Yup.number()
      .required("required")
      .max(Payments?.MAX_VALUE, `validation.value_must_be_less_than_900000`)
      .typeError("validation.Must_be_a_number"),
    details: Yup.string().required("validation.required"),
    receipt_number: Yup.string().required("validation.required"),
    date: Yup.string().required("validation.required"),
  });
};

export const getValidationSchemaADD = () => {
  // validate input
  return Yup.object().shape({
    registration_record_id: Yup.string().required("validation.required"),
    type: Yup.string().required("validation.type_required"),
    value: Yup.number()
      .required("validation.required")
      .max(Payments?.MAX_VALUE, `.value_must_be_less_than_900000`)
      .typeError("validation.Must_be_a_number"),
    details: Yup.string().required("validation.required"),
    receipt_number: Yup.string().required("validation.required"),
    date: Yup.string().required("validation.required"),
  });
};
