module CMudTreatmentProblems
    use SimulationVariables
	implicit none    
	public 
    contains   
    subroutine MudTreatmentProblemsToJson(parent)

        type(json_value),pointer :: parent
        type(json_core) :: json
        type(json_value),pointer :: p

        ! 1. create new node
        call json%create_object(p,'MudTreatmentProblems')
        
        ! 2. add member of data type to new node
        call ProblemToJson(p,"Degasser",data%problems%MudTreatmentProblems%Degasser)
        call ProblemToJson(p,"ShaleShaker",data%problems%MudTreatmentProblems%ShaleShaker)
        call ProblemToJson(p,"Desander",data%problems%MudTreatmentProblems%Desander)
        call ProblemToJson(p,"Desilter",data%problems%MudTreatmentProblems%Desilter)
        ! 3. add new node to parent
        call json%add(parent,p)
    end subroutine

    subroutine ProcessMudTreatmentProblemsDueTime(time)
        implicit none
        integer :: time
        
        if(data%problems%MudTreatmentProblems%Degasser%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%MudTreatmentProblems%Degasser, ChangeDegasser, time)
        if(data%problems%MudTreatmentProblems%ShaleShaker%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%MudTreatmentProblems%ShaleShaker, ChangeShaleShaker, time)
        if(data%problems%MudTreatmentProblems%Desander%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%MudTreatmentProblems%Desander, ChangeDesander, time)
        if(data%problems%MudTreatmentProblems%Desilter%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%MudTreatmentProblems%Desilter, ChangeDesilter, time)
        
    end subroutine
	
	
	subroutine ProcessMudTreatmentProblemsDuePumpStrokes(strokes)
        implicit none
        integer :: strokes
        
        if(data%problems%MudTreatmentProblems%Degasser%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%MudTreatmentProblems%Degasser, ChangeDegasser, strokes)
        if(data%problems%MudTreatmentProblems%ShaleShaker%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%MudTreatmentProblems%ShaleShaker, ChangeShaleShaker, strokes)
        if(data%problems%MudTreatmentProblems%Desander%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%MudTreatmentProblems%Desander, ChangeDesander, strokes)
        if(data%problems%MudTreatmentProblems%Desilter%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%MudTreatmentProblems%Desilter, ChangeDesilter, strokes)
        
    end subroutine
	
	
	subroutine ProcessMudTreatmentProblemsDueVolumePumped(volume)
        implicit none
        real(8) :: volume
        
        if(data%problems%MudTreatmentProblems%Degasser%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%MudTreatmentProblems%Degasser, ChangeDegasser, volume)
        if(data%problems%MudTreatmentProblems%ShaleShaker%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%MudTreatmentProblems%ShaleShaker, ChangeShaleShaker, volume)
        if(data%problems%MudTreatmentProblems%Desander%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%MudTreatmentProblems%Desander, ChangeDesander, volume)
        if(data%problems%MudTreatmentProblems%Desilter%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%MudTreatmentProblems%Desilter, ChangeDesilter, volume)
        
    end subroutine
	
	subroutine ProcessMudTreatmentProblemsDueDistanceDrilled(distance)
        implicit none
        real(8) :: distance
        
        if(data%problems%MudTreatmentProblems%Degasser%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%MudTreatmentProblems%Degasser, ChangeDegasser, distance)
        if(data%problems%MudTreatmentProblems%ShaleShaker%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%MudTreatmentProblems%ShaleShaker, ChangeShaleShaker, distance)
        if(data%problems%MudTreatmentProblems%Desander%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%MudTreatmentProblems%Desander, ChangeDesander, distance)
        if(data%problems%MudTreatmentProblems%Desilter%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%MudTreatmentProblems%Desilter, ChangeDesilter, distance)
        
    end subroutine
    
    
    
    
    
    
    
    subroutine ChangeDegasser(status)
        implicit none
        integer, intent (in) :: status
        !if(associated(DegasserPtr)) call DegasserPtr(status)
        !if(status == Clear_StatusType) print*,'On_Degasser_Clear'
        !if(status == Executed_StatusType) print*,'On_Degasser_Execute'
    endsubroutine
    
    subroutine ChangeShaleShaker(status)
        implicit none
        integer, intent (in) :: status
        !if(associated(ShaleShakerPtr)) call ShaleShakerPtr(status)
        !if(status == Clear_StatusType) print*,'On_ShaleShaker_Clear'
        !if(status == Executed_StatusType) print*,'On_ShaleShaker_Execute'
    endsubroutine
    
    subroutine ChangeDesander(status)
        implicit none
        integer, intent (in) :: status
        !if(associated(DesanderPtr)) call DesanderPtr(status)
        !if(status == Clear_StatusType) print*,'On_Desander_Clear'
        !if(status == Executed_StatusType) print*,'On_Desander_Execute'
    endsubroutine
    
    subroutine ChangeDesilter(status)
        implicit none
        integer, intent (in) :: status
        !if(associated(DesilterPtr)) call DesilterPtr(status)
        !if(status == Clear_StatusType) print*,'On_Desilter_Clear'
        !if(status == Executed_StatusType) print*,'On_Desilter_Execute'
    endsubroutine

end module CMudTreatmentProblems