use std::{collections::BTreeSet, net::IpAddr};
use colored::Colorize;
use derive_more::From;
use prettytable::{row, Row};
use serde::Serialize;
use super::status::SubscanModuleStatus;
use crate::{error::ModuleErrorKind, types::core::Subdomain};
pub type SubscanResultItems = BTreeSet<SubscanResultItem>;
#[derive(Clone, Debug, From, PartialEq)]
#[from((&str, &Subdomain))]
pub struct SubscanModuleResultItem {
pub module: String,
pub subdomain: Subdomain,
}
#[derive(Clone, Debug, From, PartialEq)]
#[from((&str, ModuleErrorKind))]
#[from((&str, SubscanModuleStatus))]
#[from((&str, &str))]
pub struct SubscanModuleStatusItem {
pub module: String,
pub status: SubscanModuleStatus,
}
impl SubscanModuleStatusItem {
pub async fn log(&self) {
self.status.log(&self.module);
}
}
#[derive(Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd, Serialize)]
pub struct SubscanResultItem {
pub subdomain: Subdomain,
pub ip: Option<IpAddr>,
}
impl SubscanResultItem {
pub fn as_txt(&self) -> String {
format!(
"{}\t{}",
self.subdomain,
self.ip.map_or("".to_string(), |ip| ip.to_string())
)
}
pub fn as_table_row(&self) -> Row {
row![
self.subdomain,
self.ip.map_or("".to_string(), |ip| ip.to_string())
]
}
pub async fn log(&self) {
log::info!("{}", self.as_txt().white());
}
}