package perfect

import "errors"

type Classification int

const (
	ClassificationPerfect = iota
	ClassificationDeficient
	ClassificationAbundant
)

const testVersion = 1

var ErrOnlyPositive error

func Classify(inp uint64) (Classification, error) {
	ErrOnlyPositive = errors.New("Only Positive Allowed")
	if inp <= 0 {
		return 0, ErrOnlyPositive
	}
	factors := GetFactorSum(inp)
	if factors > inp {
		return ClassificationAbundant, nil
	}
	if factors < inp {
		return ClassificationDeficient, nil
	}
	return ClassificationPerfect, nil
}

func GetFactorSum(inp uint64) uint64 {
	var ret uint64
	for i := uint64(1); i < inp; i++ {
		if inp%i == 0 {
			ret += i
		}
	}
	return ret
}
