#[derive(Clone,Copy,Debug,Hash,Eq,PartialEq)]
pub struct RobloxAssetId(pub u64);
#[derive(Debug)]
pub enum RobloxAssetIdParseErr{
	Url(url::ParseError),
	UnknownScheme,
	ParseInt(std::num::ParseIntError),
	MissingAssetId,
	MissingIDQueryParam,
}
impl std::fmt::Display for RobloxAssetIdParseErr{
	fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
		write!(f,"{self:?}")
	}
}
impl std::error::Error for RobloxAssetIdParseErr{}
impl std::str::FromStr for RobloxAssetId{
	type Err=RobloxAssetIdParseErr;
	fn from_str(s:&str)->Result<Self,Self::Err>{
		let url=url::Url::parse(s).map_err(RobloxAssetIdParseErr::Url)?;
		let parsed_asset_id=match url.scheme(){
			"rbxassetid"=>url.domain().ok_or(RobloxAssetIdParseErr::MissingAssetId)?.parse(),
			"http"|"https"=>{
				let (_,asset_id)=url.query_pairs()
				.find(|(id,_)|match id.as_ref(){
					"ID"|"id"|"Id"|"iD"=>true,
					_=>false,
				}).ok_or(RobloxAssetIdParseErr::MissingIDQueryParam)?;
				asset_id.parse()
			},
			_=>Err(RobloxAssetIdParseErr::UnknownScheme)?,
		};
		Ok(Self(parsed_asset_id.map_err(RobloxAssetIdParseErr::ParseInt)?))
	}
}

#[test]
fn test_rbxassetid(){
	let content="rbxassetid://255299419";
	let RobloxAssetId(_asset_id)=content.parse().unwrap();
}
