module CDrillStemProblems
	use SimulationVariables
	implicit none    
	public 
    contains
    subroutine DrillStemProblemsToJson(parent)
        type(json_value),pointer :: parent
        type(json_core) :: json
        type(json_value),pointer :: p

        ! 1. create new node
        call json%create_object(p,'DrillStemsProblems')
        
        ! 2. add member of data type to new node
        call ProblemToJson(p,"StringDragIncrease",data%problems%DrillStemProblems%StringDragIncrease)
        call ProblemToJson(p,"StringTorqueIncrease",data%problems%DrillStemProblems%StringTorqueIncrease)
        call ProblemToJson(p,"StringTorqueFluctuation",data%problems%DrillStemProblems%StringTorqueFluctuation)
        call json%add(p,"StringDragIncreaseTime",data%problems%DrillStemProblems%StringDragIncreaseTime)
        call json%add(p,"StringTorqueIncreaseTime",data%problems%DrillStemProblems%StringTorqueIncreaseTime)        
        ! 3. add new node to parent
        call json%add(parent,p)
    end subroutine

    subroutine ProcessDrillStemProblemsDueTime(time)
        implicit none
        integer :: time
        if(data%problems%DrillStemProblems%StringDragIncrease%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%DrillStemProblems%StringDragIncrease, ChangeStringDragIncrease, time)
        if(data%problems%DrillStemProblems%StringTorqueIncrease%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%DrillStemProblems%StringTorqueIncrease, ChangeStringTorqueIncrease, time)
        if(data%problems%DrillStemProblems%StringTorqueFluctuation%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%DrillStemProblems%StringTorqueFluctuation, ChangeStringTorqueFluctuation, time)
    end subroutine
	
	subroutine ProcessDrillStemProblemsDuePumpStrokes(strokes)
        implicit none
        integer :: strokes
        if(data%problems%DrillStemProblems%StringDragIncrease%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%DrillStemProblems%StringDragIncrease, ChangeStringDragIncrease, strokes)
        if(data%problems%DrillStemProblems%StringTorqueIncrease%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%DrillStemProblems%StringTorqueIncrease, ChangeStringTorqueIncrease, strokes)
        if(data%problems%DrillStemProblems%StringTorqueFluctuation%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%DrillStemProblems%StringTorqueFluctuation, ChangeStringTorqueFluctuation, strokes)
    end subroutine
	
	subroutine ProcessDrillStemProblemsDueVolumePumped(volume)
        implicit none
        real(8) :: volume
        if(data%problems%DrillStemProblems%StringDragIncrease%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%DrillStemProblems%StringDragIncrease, ChangeStringDragIncrease, volume)
        if(data%problems%DrillStemProblems%StringTorqueIncrease%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%DrillStemProblems%StringTorqueIncrease, ChangeStringTorqueIncrease, volume)
        if(data%problems%DrillStemProblems%StringTorqueFluctuation%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%DrillStemProblems%StringTorqueFluctuation, ChangeStringTorqueFluctuation, volume)
    end subroutine
	
	subroutine ProcessDrillStemProblemsDueDistanceDrilled(distance)
        implicit none
        real(8) :: distance
        if(data%problems%DrillStemProblems%StringDragIncrease%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%DrillStemProblems%StringDragIncrease, ChangeStringDragIncrease, distance)
        if(data%problems%DrillStemProblems%StringTorqueIncrease%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%DrillStemProblems%StringTorqueIncrease, ChangeStringTorqueIncrease, distance)
        if(data%problems%DrillStemProblems%StringTorqueFluctuation%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%DrillStemProblems%StringTorqueFluctuation, ChangeStringTorqueFluctuation, distance)
    end subroutine
	
	
    
    subroutine ChangeStringDragIncrease(status)
        implicit none
        integer, intent (in) :: status
        ! if(associated(StringDragIncreasePtr)) call StringDragIncreasePtr(status)
        !if(status == Clear_StatusType) print*,'On_StringDragIncrease_Clear'
        !if(status == Executed_StatusType) print*,'On_StringDragIncrease_Execute'
    endsubroutine
    
    subroutine ChangeStringTorqueIncrease(status)
        implicit none
        integer, intent (in) :: status
        ! if(associated(StringTorqueIncreasePtr)) call StringTorqueIncreasePtr(status)
        !if(status == Clear_StatusType) print*,'On_StringTorqueIncrease_Clear'
        !if(status == Executed_StatusType) print*,'On_StringTorqueIncrease_Execute'
    endsubroutine
    
    subroutine ChangeStringTorqueFluctuation(status)
        implicit none
        integer, intent (in) :: status
        ! if(associated(StringTorqueFluctuationPtr)) call StringTorqueFluctuationPtr(status)
        !if(status == Clear_StatusType) print*,'On_StringTorqueFluctuation_Clear'
        !if(status == Executed_StatusType) print*,'On_StringTorqueFluctuation_Execute'
    endsubroutine

end module CDrillStemProblems