package nextcloud

import "strings"

// ParseOCPermissionLetters maps Nextcloud WebDAV oc:permissions letters to OCS bitmask.
// S=share(16), R=read(1), C=create(4), W=update(2), D=delete(8).
func ParseOCPermissionLetters(raw string) int {
	raw = strings.ToUpper(strings.TrimSpace(raw))
	var perms int
	for _, ch := range raw {
		switch ch {
		case 'S':
			perms |= 16
		case 'R':
			perms |= 1
		case 'C':
			perms |= 4
		case 'W':
			perms |= 2
		case 'D':
			perms |= 8
		}
	}
	return perms
}

func PublicShareCanRead(perms int) bool   { return perms&1 != 0 }
func PublicShareCanUpdate(perms int) bool { return perms&2 != 0 }
func PublicShareCanCreate(perms int) bool { return perms&4 != 0 }
func PublicShareCanDelete(perms int) bool { return perms&8 != 0 }
