# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CHoistingProblems.f90"
module CHoistingProblems
    use SimulationVariables
	implicit none    
	public 
    contains
    subroutine HoistingProblemsFromJson(parent)
        type(json_value),pointer :: parent
        type(json_core) :: json
        type(json_value),pointer :: p

        call json%get(parent,'HoistingProblems',p)
        call ProblemFromJson(p,"MotorFail",data%problems%HoistingProblems%MotorFail)
        call ProblemFromJson(p,"ClutchEngage",data%problems%HoistingProblems%ClutchEngage)
        call ProblemFromJson(p,"ClutchDisengage",data%problems%HoistingProblems%ClutchDisengage)
    end subroutine
    
    subroutine HoistingProblemsToJson(parent)

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

! 1. create new node
        call json%create_object(p,'HoistingProblems')
        
! 2. add member of data type to new node
        call ProblemToJson(p,"MotorFail",data%problems%HoistingProblems%MotorFail)
        call ProblemToJson(p,"ClutchEngage",data%problems%HoistingProblems%ClutchEngage)
        call ProblemToJson(p,"ClutchDisengage",data%problems%HoistingProblems%ClutchDisengage)

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

    subroutine ProcessHoistingProblemsDueTime(time)
        implicit none
        integer :: time
        if(data%problems%HoistingProblems%MotorFail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%HoistingProblems%MotorFail, ChangeMotorFail, time)
        if(data%problems%HoistingProblems%ClutchEngage%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%HoistingProblems%ClutchEngage, ChangeClutchEngage, time)
        if(data%problems%HoistingProblems%ClutchDisengage%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%HoistingProblems%ClutchDisengage, ChangeClutchDisengage, time)
    end subroutine
	
	subroutine ProcessHoistingProblemsDuePumpStrokes(strokes)
        implicit none
        integer :: strokes
        if(data%problems%HoistingProblems%MotorFail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%HoistingProblems%MotorFail, ChangeMotorFail, strokes)
        if(data%problems%HoistingProblems%ClutchEngage%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%HoistingProblems%ClutchEngage, ChangeClutchEngage, strokes)
        if(data%problems%HoistingProblems%ClutchDisengage%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%HoistingProblems%ClutchDisengage, ChangeClutchDisengage, strokes)
    end subroutine
	
	subroutine ProcessHoistingProblemsDueVolumePumped(volume)
        implicit none
        real(8) :: volume
        if(data%problems%HoistingProblems%MotorFail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%HoistingProblems%MotorFail, ChangeMotorFail, volume)
        if(data%problems%HoistingProblems%ClutchEngage%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%HoistingProblems%ClutchEngage, ChangeClutchEngage, volume)
        if(data%problems%HoistingProblems%ClutchDisengage%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%HoistingProblems%ClutchDisengage, ChangeClutchDisengage, volume)
    end subroutine
	
	subroutine ProcessHoistingProblemsDueDistanceDrilled(distance)
        implicit none
        real(8) :: distance
        if(data%problems%HoistingProblems%MotorFail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%HoistingProblems%MotorFail, ChangeMotorFail, distance)
        if(data%problems%HoistingProblems%ClutchEngage%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%HoistingProblems%ClutchEngage, ChangeClutchEngage, distance)
        if(data%problems%HoistingProblems%ClutchDisengage%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%HoistingProblems%ClutchDisengage, ChangeClutchDisengage, distance)
    end subroutine
	
	
	
	
	
    
    subroutine ChangeMotorFail(status)
        use SimulationVariables !@
        implicit none
        integer, intent (in) :: status
! if(associated(MotorFailPtr)) call MotorFailPtr(status)
        if(status == Clear_StatusType)     data%State%Drawworks%MotorFaileMalf=0
        if(status == Executed_StatusType)  data%State%Drawworks%MotorFaileMalf=1
    endsubroutine
    
    subroutine ChangeClutchEngage(status)
        use SimulationVariables !@
        implicit none
        integer, intent (in) :: status
! if(associated(ClutchEngagePtr)) call ClutchEngagePtr(status)
        if(status == Clear_StatusType)     data%State%Drawworks%ClutchEngageMalf=0
        if(status == Executed_StatusType)  data%State%Drawworks%ClutchEngageMalf=1
    endsubroutine
    
    subroutine ChangeClutchDisengage(status)
        use SimulationVariables !@
        implicit none
        integer, intent (in) :: status
! if(associated(ClutchDisengagePtr)) call ClutchDisengagePtr(status)
        if(status == Clear_StatusType)     data%State%Drawworks%ClutchDisengageMalf=0
        if(status == Executed_StatusType)  data%State%Drawworks%ClutchDisengageMalf=1
    endsubroutine

end module CHoistingProblems