module COtherProblems
    use SimulationVariables
	implicit none    
	public 
    contains
    subroutine OtherProblemsToJson(parent)

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

        ! 1. create new node
        call json%create_object(p,'OtherProblems')
        
        ! 2. add member of data type to new node
        call ProblemToJson(p,"RigAlarm",data%problems%OtherProblems%RigAlarm)
        call ProblemToJson(p,"RigWaterSupply",data%problems%OtherProblems%RigWaterSupply)
        call ProblemToJson(p,"RigAir",data%problems%OtherProblems%RigAir)
        call ProblemToJson(p,"Gen1",data%problems%OtherProblems%Gen1)
        call ProblemToJson(p,"Gen2",data%problems%OtherProblems%Gen2)
        call ProblemToJson(p,"Gen3",data%problems%OtherProblems%Gen3)
        call ProblemToJson(p,"Gen4",data%problems%OtherProblems%Gen4)
        call ProblemToJson(p,"Scr1",data%problems%OtherProblems%Scr1)
        call ProblemToJson(p,"Scr2",data%problems%OtherProblems%Scr2)
        call ProblemToJson(p,"Scr3",data%problems%OtherProblems%Scr3)
        call ProblemToJson(p,"Scr4",data%problems%OtherProblems%Scr4)

        ! 3. add new node to parent
        call json%add(parent,p)
    end subroutine

    subroutine ProcessOtherProblemsDueTime(time)
        implicit none
        integer :: time
        
        if(data%problems%OtherProblems%RigAlarm%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%RigAlarm, ChangeRigAlarm, time)
        if(data%problems%OtherProblems%RigWaterSupply%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%RigWaterSupply, ChangeRigWaterSupply, time)
        if(data%problems%OtherProblems%RigAir%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%RigAir, ChangeRigAir, time)
        if(data%problems%OtherProblems%Gen1%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%Gen1, ChangeGen1, time)
        if(data%problems%OtherProblems%Gen2%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%Gen2, ChangeGen2, time)
        if(data%problems%OtherProblems%Gen3%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%Gen3, ChangeGen3, time)
        if(data%problems%OtherProblems%Gen4%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%Gen4, ChangeGen4, time)
        if(data%problems%OtherProblems%Scr1%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%Scr1, ChangeScr1, time)
        if(data%problems%OtherProblems%Scr2%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%Scr2, ChangeScr2, time)
        if(data%problems%OtherProblems%Scr3%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%Scr3, ChangeScr3, time)
        if(data%problems%OtherProblems%Scr4%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%Scr4, ChangeScr4, time)
        
    end subroutine
	
	subroutine ProcessOtherProblemsDuePumpStrokes(strokes)
        implicit none
        integer :: strokes
        
        if(data%problems%OtherProblems%RigAlarm%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%RigAlarm, ChangeRigAlarm, strokes)
        if(data%problems%OtherProblems%RigWaterSupply%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%RigWaterSupply, ChangeRigWaterSupply, strokes)
        if(data%problems%OtherProblems%RigAir%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%RigAir, ChangeRigAir, strokes)
        if(data%problems%OtherProblems%Gen1%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%Gen1, ChangeGen1, strokes)
        if(data%problems%OtherProblems%Gen2%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%Gen2, ChangeGen2, strokes)
        if(data%problems%OtherProblems%Gen3%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%Gen3, ChangeGen3, strokes)
        if(data%problems%OtherProblems%Gen4%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%Gen4, ChangeGen4, strokes)
        if(data%problems%OtherProblems%Scr1%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%Scr1, ChangeScr1, strokes)
        if(data%problems%OtherProblems%Scr2%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%Scr2, ChangeScr2, strokes)
        if(data%problems%OtherProblems%Scr3%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%Scr3, ChangeScr3, strokes)
        if(data%problems%OtherProblems%Scr4%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%Scr4, ChangeScr4, strokes)
        
    end subroutine
	
	subroutine ProcessOtherProblemsDueVolumePumped(volume)
        implicit none
        real(8) :: volume
        
        if(data%problems%OtherProblems%RigAlarm%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%RigAlarm, ChangeRigAlarm, volume)
        if(data%problems%OtherProblems%RigWaterSupply%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%RigWaterSupply, ChangeRigWaterSupply, volume)
        if(data%problems%OtherProblems%RigAir%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%RigAir, ChangeRigAir, volume)
        if(data%problems%OtherProblems%Gen1%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%Gen1, ChangeGen1, volume)
        if(data%problems%OtherProblems%Gen2%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%Gen2, ChangeGen2, volume)
        if(data%problems%OtherProblems%Gen3%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%Gen3, ChangeGen3, volume)
        if(data%problems%OtherProblems%Gen4%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%Gen4, ChangeGen4, volume)
        if(data%problems%OtherProblems%Scr1%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%Scr1, ChangeScr1, volume)
        if(data%problems%OtherProblems%Scr2%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%Scr2, ChangeScr2, volume)
        if(data%problems%OtherProblems%Scr3%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%Scr3, ChangeScr3, volume)
        if(data%problems%OtherProblems%Scr4%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%Scr4, ChangeScr4, volume)
        
    end subroutine
	
	subroutine ProcessOtherProblemsDueDistanceDrilled(distance)
        implicit none
        real(8) :: distance
        
        if(data%problems%OtherProblems%RigAlarm%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%RigAlarm, ChangeRigAlarm, distance)
        if(data%problems%OtherProblems%RigWaterSupply%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%RigWaterSupply, ChangeRigWaterSupply, distance)
        if(data%problems%OtherProblems%RigAir%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%RigAir, ChangeRigAir, distance)
        if(data%problems%OtherProblems%Gen1%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%Gen1, ChangeGen1, distance)
        if(data%problems%OtherProblems%Gen2%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%Gen2, ChangeGen2, distance)
        if(data%problems%OtherProblems%Gen3%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%Gen3, ChangeGen3, distance)
        if(data%problems%OtherProblems%Gen4%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%Gen4, ChangeGen4, distance)
        if(data%problems%OtherProblems%Scr1%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%Scr1, ChangeScr1, distance)
        if(data%problems%OtherProblems%Scr2%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%Scr2, ChangeScr2, distance)
        if(data%problems%OtherProblems%Scr3%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%Scr3, ChangeScr3, distance)
        if(data%problems%OtherProblems%Scr4%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%Scr4, ChangeScr4, distance)
        
    end subroutine
    
    
    subroutine ChangeRigAlarm(status)
        implicit none
        integer, intent (in) :: status
        !if(associated(RigAlarmPtr)) call RigAlarmPtr(status)
        !if(status == Clear_StatusType) print*,'On_RigAlarm_Clear'
        !if(status == Executed_StatusType) print*,'On_RigAlarm_Execute'
    endsubroutine
    
    subroutine ChangeRigWaterSupply(status)
        implicit none
        integer, intent (in) :: status
        !if(associated(RigWaterSupplyPtr)) call RigWaterSupplyPtr(status)
        !if(status == Clear_StatusType) print*,'On_RigWaterSupply_Clear'
        !if(status == Executed_StatusType) print*,'On_RigWaterSupply_Execute'
    endsubroutine
    
    subroutine ChangeRigAir(status)
        use SimulationVariables
        implicit none
        integer, intent (in) :: status
        !if(associated(RigAirPtr)) call RigAirPtr(status)
        if(status == Clear_StatusType)          data%State%BopStackAcc%RigAirMalf = 0
        if(status == Executed_StatusType)       data%State%BopStackAcc%RigAirMalf = 1
    endsubroutine
    
    subroutine ChangeGen1(status)
        implicit none
        integer, intent (in) :: status
        !if(associated(Gen1Ptr)) call Gen1Ptr(status)
        !if(status == Clear_StatusType) print*,'On_Gen1_Clear'
        !if(status == Executed_StatusType) print*,'On_Gen1_Execute'
    endsubroutine
    
    subroutine ChangeGen2(status)
        implicit none
        integer, intent (in) :: status
        !if(associated(Gen2Ptr)) call Gen2Ptr(status)
        !if(status == Clear_StatusType) print*,'On_Gen2_Clear'
        !if(status == Executed_StatusType) print*,'On_Gen2_Execute'
    endsubroutine
    
    subroutine ChangeGen3(status)
        implicit none
        integer, intent (in) :: status
        !if(associated(Gen3Ptr)) call Gen3Ptr(status)
        !if(status == Clear_StatusType) print*,'On_Gen3_Clear'
        !if(status == Executed_StatusType) print*,'On_Gen3_Execute'
    endsubroutine
    
    subroutine ChangeGen4(status)
        implicit none
        integer, intent (in) :: status
        !if(associated(Gen4Ptr)) call Gen4Ptr(status)
        !if(status == Clear_StatusType) print*,'On_Gen4_Clear'
        !if(status == Executed_StatusType) print*,'On_Gen4_Execute'
    endsubroutine
    
    subroutine ChangeScr1(status)
        implicit none
        integer, intent (in) :: status
        !if(associated(Scr1Ptr)) call Scr1Ptr(status)
        !if(status == Clear_StatusType) print*,'On_Scr1_Clear'
        !if(status == Executed_StatusType) print*,'On_Scr1_Execute'
    endsubroutine
    
    subroutine ChangeScr2(status)
        implicit none
        integer, intent (in) :: status
        !if(associated(Scr2Ptr)) call Scr2Ptr(status)
        !if(status == Clear_StatusType) print*,'On_Scr2_Clear'
        !if(status == Executed_StatusType) print*,'On_Scr2_Execute'
    endsubroutine
    
    subroutine ChangeScr3(status)
        implicit none
        integer, intent (in) :: status
        !if(associated(Scr3Ptr)) call Scr3Ptr(status)
        !if(status == Clear_StatusType) print*,'On_Scr3_Clear'
        !if(status == Executed_StatusType) print*,'On_Scr3_Execute'
    endsubroutine
    
    subroutine ChangeScr4(status)
        implicit none
        integer, intent (in) :: status
        !if(associated(Scr4Ptr)) call Scr4Ptr(status)
        !if(status == Clear_StatusType) print*,'On_Scr4_Clear'
        !if(status == Executed_StatusType) print*,'On_Scr4_Execute'
    endsubroutine


end module COtherProblems