use jam_types::Hash;

#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Debug)]
pub enum CodeInfo<T> {
	Known(T),
	Undefined(Hash),
	CodeNotProvided(Hash),
}
impl<T> CodeInfo<T> {
	pub fn as_ref(&self) -> CodeInfo<&T> {
		match self {
			CodeInfo::Known(ref x) => CodeInfo::Known(x),
			CodeInfo::CodeNotProvided(ref h) => CodeInfo::CodeNotProvided(*h),
			CodeInfo::Undefined(ref h) => CodeInfo::Undefined(*h),
		}
	}
	pub fn map<R>(self, f: impl FnOnce(T) -> R) -> CodeInfo<R> {
		match self {
			CodeInfo::Known(x) => CodeInfo::Known(f(x)),
			CodeInfo::CodeNotProvided(h) => CodeInfo::CodeNotProvided(h),
			CodeInfo::Undefined(h) => CodeInfo::Undefined(h),
		}
	}
}
