// Copyright (C) 2016 Kohei YOSHIDA. All rights reserved.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of The BSD 3-Clause License
// that can be found in the LICENSE file.

package uritemplate

type CompareFlags uint8

const (
	CompareVarname CompareFlags = 1 << iota
)

// Equals reports whether or not two URI Templates t1 and t2 are equivalent.
func ( *Template,  *Template,  CompareFlags) bool {
	if len(.exprs) != len(.exprs) {
		return false
	}
	for  := 0;  < len(.exprs); ++ {
		switch t1 := .exprs[].(type) {
		case literals:
			,  := .exprs[].(literals)
			if ! {
				return false
			}
			if  !=  {
				return false
			}
		case *expression:
			,  := .exprs[].(*expression)
			if ! {
				return false
			}
			if .op != .op || len(.vars) != len(.vars) {
				return false
			}
			for  := 0;  < len(.vars); ++ {
				 := .vars[]
				 := .vars[]
				if &CompareVarname == CompareVarname && .name != .name {
					return false
				}
				if .maxlen != .maxlen || .explode != .explode {
					return false
				}
			}
		default:
			panic("unhandled case")
		}
	}
	return true
}