//go:build linux

package liburing

import (
	"strings"
)

const (
	IORING_SETUP_IOPOLL uint32 = 1 << iota
	IORING_SETUP_SQPOLL
	IORING_SETUP_SQ_AFF
	IORING_SETUP_CQSIZE
	IORING_SETUP_CLAMP
	IORING_SETUP_ATTACH_WQ
	IORING_SETUP_R_DISABLED
	IORING_SETUP_SUBMIT_ALL
	IORING_SETUP_COOP_TASKRUN
	IORING_SETUP_TASKRUN_FLAG
	IORING_SETUP_SQE128
	IORING_SETUP_CQE32
	IORING_SETUP_SINGLE_ISSUER
	IORING_SETUP_DEFER_TASKRUN
	IORING_SETUP_NO_MMAP
	IORING_SETUP_REGISTERED_FD_ONLY
	IORING_SETUP_NO_SQARRAY
	IORING_SETUP_HYBRID_IOPOLL
)

func ParseSetupFlags(s string) uint32 {
	s = strings.TrimSpace(s)
	s = strings.ToUpper(s)
	switch s {
	case "IORING_SETUP_IOPOLL":
		return IORING_SETUP_IOPOLL
	case "IORING_SETUP_SQPOLL":
		return IORING_SETUP_SQPOLL
	case "IORING_SETUP_SQ_AFF":
		return IORING_SETUP_SQ_AFF
	case "IORING_SETUP_CQSIZE":
		return IORING_SETUP_CQSIZE
	case "IORING_SETUP_CLAMP":
		return IORING_SETUP_CLAMP
	case "IORING_SETUP_ATTACH_WQ":
		return IORING_SETUP_ATTACH_WQ
	case "IORING_SETUP_R_DISABLED":
		return IORING_SETUP_R_DISABLED
	case "IORING_SETUP_SUBMIT_ALL":
		return IORING_SETUP_SUBMIT_ALL
	case "IORING_SETUP_COOP_TASKRUN":
		return IORING_SETUP_COOP_TASKRUN
	case "IORING_SETUP_TASKRUN_FLAG":
		return IORING_SETUP_TASKRUN_FLAG
	case "IORING_SETUP_SQE128":
		return IORING_SETUP_SQE128
	case "IORING_SETUP_CQE32":
		return IORING_SETUP_CQE32
	case "IORING_SETUP_SINGLE_ISSUER":
		return IORING_SETUP_SINGLE_ISSUER
	case "IORING_SETUP_DEFER_TASKRUN":
		return IORING_SETUP_DEFER_TASKRUN
	case "IORING_SETUP_NO_MMAP":
		return IORING_SETUP_NO_MMAP
	case "IORING_SETUP_REGISTERED_FD_ONLY":
		return IORING_SETUP_REGISTERED_FD_ONLY
	case "IORING_SETUP_NO_SQARRAY":
		return IORING_SETUP_NO_SQARRAY
	case "IORING_SETUP_HYBRID_IOPOLL":
		return IORING_SETUP_HYBRID_IOPOLL
	default:
		return 0
	}
}
