module MudPropertiesModule
    use SimulationVariables
    use json_module
    implicit none
    
    contains

    subroutine MudPropertiesToJson(parent)

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

        ! 1. create new node
        call json%create_object(p,'Mud')
        
        ! 2. add member of data type to new node
        call json%add(p,"ActiveMudType",data%Configuration%Mud%ActiveMudType)
        call json%add(p,"ActiveRheologyModel",data%Configuration%Mud%ActiveRheologyModel)
        call json%add(p,"ActiveMudVolume",data%Configuration%Mud%ActiveMudVolume)
        call json%add(p,"ActiveMudVolumeGal",data%Configuration%Mud%ActiveMudVolumeGal)
        call json%add(p,"ActiveDensity",data%Configuration%Mud%ActiveDensity)
        call json%add(p,"ActivePlasticViscosity",data%Configuration%Mud%ActivePlasticViscosity)
        call json%add(p,"ActiveYieldPoint",data%Configuration%Mud%ActiveYieldPoint)
        call json%add(p,"ActiveThetaThreeHundred",data%Configuration%Mud%ActiveThetaThreeHundred)
        call json%add(p,"ActiveThetaSixHundred",data%Configuration%Mud%ActiveThetaSixHundred)
        call json%add(p,"ReserveMudType",data%Configuration%Mud%ReserveMudType)
        call json%add(p,"ReserveMudVolume",data%Configuration%Mud%ReserveMudVolume)
        call json%add(p,"ReserveMudVolumeGal",data%Configuration%Mud%ReserveMudVolumeGal)
        call json%add(p,"ReserveDensity",data%Configuration%Mud%ReserveDensity)
        call json%add(p,"ReservePlasticViscosity",data%Configuration%Mud%ReservePlasticViscosity)
        call json%add(p,"ReserveYieldPoint",data%Configuration%Mud%ReserveYieldPoint)
        call json%add(p,"ReserveThetaThreeHundred",data%Configuration%Mud%ReserveThetaThreeHundred)
        call json%add(p,"ReserveThetaSixHundred",data%Configuration%Mud%ReserveThetaSixHundred)
        call json%add(p,"ActiveTotalTankCapacity",data%Configuration%Mud%ActiveTotalTankCapacity)
        call json%add(p,"ActiveTotalTankCapacityGal",data%Configuration%Mud%ActiveTotalTankCapacityGal)
        call json%add(p,"ActiveSettledContents",data%Configuration%Mud%ActiveSettledContents)
        call json%add(p,"ActiveSettledContentsGal",data%Configuration%Mud%ActiveSettledContentsGal)
        call json%add(p,"ActiveTotalContents",data%Configuration%Mud%ActiveTotalContents)
        call json%add(p,"ActiveTotalContentsGal",data%Configuration%Mud%ActiveTotalContentsGal)
        call json%add(p,"ActiveAutoDensity",data%Configuration%Mud%ActiveAutoDensity)
        call json%add(p,"InitialTripTankMudVolume",data%Configuration%Mud%InitialTripTankMudVolume)
        call json%add(p,"InitialTripTankMudVolumeGal",data%Configuration%Mud%InitialTripTankMudVolumeGal)
        call json%add(p,"PedalFlowMeter",data%Configuration%Mud%PedalFlowMeter)
        
        ! 3. add new node to parent
        call json%add(parent,p)
    end subroutine

    
    subroutine Set_ActiveMudVolume_StudentStation(v)
        implicit none
        real*8, intent(in) :: v
        #ifdef ExcludeExtraChanges
                if(data%Configuration%Mud%ActiveMudVolume == v) return
        #endif
        data%Configuration%Mud%ActiveMudVolume = v   
        ! if(associated(ActiveMudVolumePtr)) call ActiveMudVolumePtr(data%Configuration%Mud%ActiveMudVolume)
    end subroutine
        
    subroutine Set_ActiveDensity_StudentStation(v)
        implicit none
        real*8, intent(in) :: v
        #ifdef ExcludeExtraChanges
                if(data%Configuration%Mud%ActiveDensity == v) return
        #endif
        data%Configuration%Mud%ActiveDensity = v    
        ! if(associated(ActiveDensityPtr)) call ActiveDensityPtr(data%Configuration%Mud%ActiveDensity)
    end subroutine
    
    subroutine Set_ReserveMudVolume_StudentStation(v)
        implicit none
        real*8, intent(in) :: v
        #ifdef ExcludeExtraChanges
                if(data%Configuration%Mud%ReserveMudVolume == v) return
        #endif
        data%Configuration%Mud%ReserveMudVolume = v  
        ! if(associated(ReserveMudVolumePtr)) call ReserveMudVolumePtr(data%Configuration%Mud%ReserveMudVolume)
    end subroutine
        
    subroutine Set_ReserveDensity_StudentStation(v)
        implicit none
        real*8, intent(in) :: v
        #ifdef ExcludeExtraChanges
                if(data%Configuration%Mud%ReserveDensity == v) return
        #endif
        data%Configuration%Mud%ReserveDensity = v   
        ! if(associated(ReserveDensityPtr)) call ReserveDensityPtr(data%Configuration%Mud%ReserveDensity)
    end subroutine

end module MudPropertiesModule