// Copyright (C) 2019 Marius Schellenberger

package core

type Permission int

const (
	Invalid Permission = iota
	Public
	Private
)

func ParsePermString(p string) Permission {
	switch p {
	case "1":
		return Public
	case "2":
		return Private
	}
	return Invalid
}

func ReadPerm(username string, p Permission, s Section) bool {
	switch p {
	case Public:
		return true
	case Private:
		_, c := Contains(username, s.Members)
		return c
	}
	return false
}

func WritePerm(username string, p Permission, s Section) bool {
	switch p {
	case Public, Private:
		_, c := Contains(username, s.Members)
		return c
	}
	return false
}
