package printer

type GeneratedIdentifierFlags int

const (
	// Kind

	GeneratedIdentifierFlagsNone     = iota // Not automatically generated.
	GeneratedIdentifierFlagsAuto            // Automatically generated identifier.
	GeneratedIdentifierFlagsLoop            // Automatically generated identifier with a preference for '_i'.
	GeneratedIdentifierFlagsUnique          // Unique name based on the 'text' property.
	GeneratedIdentifierFlagsNode            // Unique name based on the node in the 'Node' property.
	GeneratedIdentifierFlagsKindMask = 7    // Mask to extract the kind of identifier from its flags.

	// Flags

	GeneratedIdentifierFlagsReservedInNestedScopes = 1 << 3 // Reserve the generated name in nested scopes
	GeneratedIdentifierFlagsOptimistic             = 1 << 4 // First instance won't use '_#' if there's no conflict
	GeneratedIdentifierFlagsFileLevel              = 1 << 5 // Use only the file identifiers list and not generated names to search for conflicts
	GeneratedIdentifierFlagsAllowNameSubstitution  = 1 << 6 // Used by `module.ts` to indicate generated nodes which can have substitutions performed upon them (as they were generated by an earlier transform phase)
)

func (f GeneratedIdentifierFlags) Kind() GeneratedIdentifierFlags {
	return f & GeneratedIdentifierFlagsKindMask
}

func (f GeneratedIdentifierFlags) IsAuto() bool {
	return f.Kind() == GeneratedIdentifierFlagsAuto
}

func (f GeneratedIdentifierFlags) IsLoop() bool {
	return f.Kind() == GeneratedIdentifierFlagsLoop
}

func (f GeneratedIdentifierFlags) IsUnique() bool {
	return f.Kind() == GeneratedIdentifierFlagsUnique
}

func (f GeneratedIdentifierFlags) IsNode() bool {
	return f.Kind() == GeneratedIdentifierFlagsNode
}

func (f GeneratedIdentifierFlags) IsReservedInNestedScopes() bool {
	return f&GeneratedIdentifierFlagsReservedInNestedScopes != 0
}

func (f GeneratedIdentifierFlags) IsOptimistic() bool {
	return f&GeneratedIdentifierFlagsOptimistic != 0
}

func (f GeneratedIdentifierFlags) IsFileLevel() bool {
	return f&GeneratedIdentifierFlagsFileLevel != 0
}

func (f GeneratedIdentifierFlags) HasAllowNameSubstitution() bool {
	return f&GeneratedIdentifierFlagsAllowNameSubstitution != 0
}
