
import * as Yup from "yup";
import { buildFormData } from "../../api/helper/buildFormData";

interface formUtilCommon {
  title:string,
  description:string ,
  image:string
}

interface ObjectToEdit extends formUtilCommon {
    id?:number,

}

export interface InitialValues extends ObjectToEdit {
  title:string,
  description:string ,
  image:string
}
interface ValidateSchema  extends formUtilCommon{

}

export const getInitialValues = (objectToEdit: ObjectToEdit | null = null): InitialValues => {
 

  return {
    id:objectToEdit?.id?? 0 ,
    title:objectToEdit?.title ?? "",
    description:objectToEdit?.description?? "",
    image:objectToEdit?.image?? "",
  }


};

export const getValidationSchema = (editMode: boolean = false): Yup.Schema<ValidateSchema> => {
    // validate input  
  return Yup.object().shape({
    title:Yup.string().required('required'),
    description:Yup.string().required("required"),
    image:Yup.string().required("required"),
  });
};

export const getDataToSend = (values: any): FormData => {
  const data = { ...values };
  
  if(typeof data['image'] == 'string') delete data['image']
  return data;
};

