module CKickProblems
    use SimulationVariables
	implicit none    
	public
    !constants
    ! integer :: Gas_FluidType = 0
    ! integer :: Oil_FluidType = 1
    ! integer :: Water_FluidType = 2
    
    contains
    subroutine KickProblemsToJson(parent)

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

        ! 1. create new node
        call json%create_object(p,'KickProblems')

        call ProblemToJson(p,"Kick",data%problems%KickProblems%Kick)
        call json%add(p,"FluidType",data%problems%KickProblems%FluidType)
        call json%add(p,"FlowRate",data%problems%KickProblems%FlowRate)
        call json%add(p,"OverBalancePressure",data%problems%KickProblems%OverBalancePressure)
        call json%add(p,"IsAutoMigrationRateSelected",data%problems%KickProblems%IsAutoMigrationRateSelected)
        call json%add(p,"AutoMigrationRate",data%problems%KickProblems%AutoMigrationRate)        ! 2. add member of data type to new node

        ! 3. add new node to parent
        call json%add(parent,p)
    end subroutine
    
    
    subroutine ProcessKickProblemsDueTime(time)
        implicit none
        integer :: time
        
        if(data%problems%KickProblems%Kick%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%KickProblems%Kick, ChangeKick, time)
        
    end subroutine
    
    subroutine ProcessKickProblemsDuePumpStrokes(strokes)
        implicit none
        integer :: strokes
        
        if(data%problems%KickProblems%Kick%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%KickProblems%Kick, ChangeKick, strokes)
        
    end subroutine
    
    subroutine ProcessKickProblemsDueVolumePumped(volume)
        implicit none
        real(8) :: volume
        
        if(data%problems%KickProblems%Kick%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%KickProblems%Kick, ChangeKick, volume)
        
    end subroutine
    
    subroutine ProcessKickProblemsDueDistanceDrilled(distance)
        implicit none
        real(8) :: distance
        
        if(data%problems%KickProblems%Kick%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%KickProblems%Kick, ChangeKick, distance)
        
    end subroutine
    
    subroutine ChangeKick(status)
        implicit none
        integer, intent (in) :: status
        ! if(associated(data%problems%KickProblems%KickPtr)) call data%problems%KickProblems%KickPtr(status)
        !if(status == Clear_StatusType) print*,'On_Kick_Clear'
        !if(status == Executed_StatusType) print*,'On_Kick_Execute'
    endsubroutine
    

end module CKickProblems