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

interface formUtilCommon {
  name:string,
  image:string 
}

interface ObjectToEdit extends formUtilCommon {

    id?:number,

}

export interface InitialValues extends ObjectToEdit {

}
interface ValidateSchema  extends formUtilCommon{

}

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

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


};

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

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

