module CHeadEnum
    use OperationScenariosModule
    implicit none
    ! enum, bind(c)
    !     enumerator FILLUP_HEAD_REMOVE
    !     enumerator FILLUP_HEAD_INSTALL
    ! end enum
    contains
    
    subroutine Set_FillupHead(v)
        use CManifolds, only: ToggleFillupHead
        implicit none
        integer , intent(in) :: v
#ifdef ExcludeExtraChanges
        if(data%State%unitySignals%FillupHead == v) return
#endif
        data%State%unitySignals%FillupHead = v
        
        if (data%State%unitySignals%FillupHead == FILLUP_HEAD_INSTALL) then
            call ToggleFillupHead(.true.)
        else if (data%State%unitySignals%FillupHead == FILLUP_HEAD_REMOVE) then
            call ToggleFillupHead(.false.)
        endif
        
#ifdef deb
	    print*, 'data%State%unitySignals%FillupHead=', data%State%unitySignals%FillupHead
#endif
        call OnFillupHeadChange%RunAll()
    end subroutine
    
    integer function Get_FillupHead()
        implicit none
        Get_FillupHead = FillupHead
    end function

    subroutine Evaluate_FillupHead()
        use CStudentStationVariables!, only: data%State%StudentStation%FillupHeadInstallation
        implicit none
        
        
        if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then
#ifdef OST
            print*, 'Evaluate_FillupHead=TopDrive'
#endif
        endif
        
        
        
        
        
        
        if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then
#ifdef OST
            print*, 'Evaluate_FillupHead=Kelly'
#endif
        endif
        
        
        if (Get_FillupHead() == FILLUP_HEAD_INSTALL) then
            data%State%StudentStation%FillupHeadInstallation = .true.
        else if (Get_FillupHead() == FILLUP_HEAD_REMOVE) then
            data%State%StudentStation%FillupHeadInstallation = .false.
        endif
        
    end subroutine
    
    ! subroutine Subscribe_FillupHead()
    !     use CStudentStationVariables
    !     implicit none
    !     call OnState%StudentStation%FillupHeadInstallationPress%Add(ButtonPress_State%StudentStation%FillupHeadInstallation)
    !     call OnFillupHeadRemovePress%Add(ButtonPress_FillupHeadRemove)
    ! end subroutine
    
    subroutine ButtonPress_FillupHeadInstallation()
        implicit none
        
        
        
        
        
        if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then
#ifdef OST
            print*, 'ButtonPress_State%StudentStation%FillupHeadInstallation=TopDrive'
#endif



            !TOPDRIVE-CODE=67
            if (Get_FillupHeadPermission()) then
                call Set_FillupHead(FILLUP_HEAD_INSTALL)
            
                return
            end if


        endif
        
        
        
        
        
        
        if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then
#ifdef OST
            print*, 'ButtonPress_State%StudentStation%FillupHeadInstallation=Kelly'
#endif


            !OPERATION-CODE=71
            if (Get_InstallFillupHeadPermission()) then
                call Set_FillupHead(FILLUP_HEAD_INSTALL)
            
                return
            end if


        endif
        
        
        
        
        
        
        
    end subroutine
    
    
    subroutine ButtonPress_FillupHeadRemove()
        implicit none
        
        
        
        
        
        if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then
#ifdef OST
            print*, 'ButtonPress_FillupHeadRemove=TopDrive'
#endif


            !TOPDRIVE-CODE=68
            if (Get_FillupHeadPermission()) then
                call Set_FillupHead(FILLUP_HEAD_REMOVE)
            
                return
            end if


        endif
        
        
        
        
        
        
        if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then
#ifdef OST
            print*, 'ButtonPress_FillupHeadRemove=Kelly'
#endif


            !OPERATION-CODE=72
            if (Get_InstallFillupHeadPermission()) then
                call Set_FillupHead(FILLUP_HEAD_REMOVE)
                return
            end if
            



        endif
        
        
        
        
        
        
    end subroutine
    
end module CHeadEnum