import * as Yup from 'yup'
import { MedicalLog_Enums, MettaSvr_Common } from '../../../../redux/helpers/action-enums'

export const validationSchema = Yup.object().shape({

    medicalLog: Yup.object().shape({
    
        dob: Yup.string()
            .required('DOB is required'),
        gender: Yup.number()
            .required('Gender is required'),
        familyHistoryIds: Yup.array()
            .test('Either N/A or others', 'Select either N/A or Others', function (value) {
                // your global test code...
                let found = value.indexOf( MedicalLog_Enums.FamilyHistoryCTEnum.NA.toString()) != -1
                // console.log(value, found)
                if (value.length > 1 &&  found){
                    return false
                }
                return true
            })
            .min(1, 'Family History is required'),  
                  
        
        addictionIds: Yup.array()
            .test('Either N/A or others', 'Select either N/A or Others', function (value) {
                // your global test code...
                let found = value.indexOf( MedicalLog_Enums.AddictionCTEnum.NA.toString()) != -1
                // console.log(value, found)
                if (value.length > 1 &&  found){
                    return false
                }                
                return true
            })
            .min(1, 'Addiction history is required'),
        heightInMeter: Yup.number()
            .required('Height is required'),
        weightInKgs: Yup.number()
            .required('Weight is required'),
        waistCurInCms: Yup.number()
            .required('Waist Circumference is required'),
        // bmi: Yup.number()
        //     .required('BMI is required'),
        bpInMmhg: Yup.string()
            .required('BP is required')
            .matches(/^\d{1,3}\/\d{1,3}$/, "BP invalid format. Should be like 120/80"),
        medicalHistory: Yup.array().of(
            Yup.object().shape({
                diseaseType: Yup.number()
                    .required('Disease type is required'),
                fromDate: Yup.string()
                    .required('FromDate is required'),
                toDate: Yup.string()
                    .required('FromDate is required')
            })
        ).min(1, 'medical history needed'),

        surgeryDetails: Yup.array().of(
            Yup.object().shape({
                surgeryName: Yup.string()
                    .required('Surgery name is required'),
                surgeryDate: Yup.string()
                    .required('Surgery Date is required')                
            })
        ).min(1, 'Surgery details needed'), 

        medications: Yup.array().of(
            Yup.object().shape({
                doses: Yup.string()
                    .required('Dosage is required'),
                medicationName: Yup.string()
                    .required('MedicineName is required'),                
                startDate: Yup.string()
                    .required('Medication Date is required')                
            })
        ).min(1, 'Medications details needed'),  


    })
})
