package server

func (server *Server) validateRow(row string) (valid bool) {
	// Declarations baby!
	valid = true
	var found bool
	var double bool
	count := make(map[rune]int)

	// 1. Make sure row is 9 in length
	if len(row) != 9 {
		valid = false
	}

	// 2. Ensure all digits are numbers
	for _, value := range row {
		found = server.validChar(value)
	}

	if !found {
		valid = false
	}

	// 3. Ensure all digits (except zero) are only present once
	for _, digits := range row {
		count[digits] = count[digits] + 1
	}

	for key, value := range count {
		if value > 1 && key != 48 {
			double = true
		}
	}

	if double {
		valid = false
	}

	return
}
