// Part of the Crubit project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

use std::borrow::Cow;
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::fmt::{self, Arguments, Display, Formatter};

use serde::Serialize;

#[doc(hidden)]
pub mod macro_internal {

    pub use anyhow;
    pub use arc_anyhow;
    pub use std::format_args;
}

/// An error that stores its format string as well as the formatted message.
#[derive(Debug, Clone)]
pub struct FormattedError {
    pub fmt: Cow<'static, str>,
    pub message: Cow<'static, str>,
}

impl FormattedError {
    pub fn new_static(fmt: &'static str, args: Arguments) -> arc_anyhow::Error {
        arc_anyhow::Error::from(anyhow::Error::from(match args.as_str() {
            // This format string has no parameters to format at runtime.
            // Note: The compiler can perform optimizations to return `Some`, when even when
            // `fmt` contains placeholders, so we store `fmt` instead of `s` for `fmt` field.
            Some(s) => Self { fmt: Cow::Borrowed(fmt), message: Cow::Borrowed(s) },
            // This format string has parameters and must be formatted.
            None => Self { fmt: Cow::Borrowed(fmt), message: Cow::Owned(fmt::format(args)) },
        }))
    }

    pub fn new_dynamic(err: impl Display) -> arc_anyhow::Error {
        // Use the whole error as the format string. This is preferable to
        // grouping all dynamic errors under the "{}" format string.
        let message = format!("{}", err);
        arc_anyhow::Error::from(anyhow::Error::from(Self {
            fmt: Cow::Owned(message.clone()),
            message: Cow::Owned(message),
        }))
    }
}

impl Display for FormattedError {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        write!(f, "{}", self.message)
    }
}

impl std::error::Error for FormattedError {}

/// Evaluates to an [`arc_anyhow::Error`].
///
/// Otherwise similar to [`anyhow::anyhow`].
#[macro_export]
macro_rules! anyhow {
    ($fmt:literal $(,)?) => {
        $crate::FormattedError::new_static(
            $fmt,
            $crate::macro_internal::format_args!($fmt),
        )
    };
    ($err:expr $(,)?) => {
        $crate::FormattedError::new_dynamic($err)
    };
    ($fmt:expr, $($arg:tt)*) => {
        $crate::FormattedError::new_static(
            $fmt,
            $crate::macro_internal::format_args!($fmt, $($arg)*),
        )
    };
}

/// Returns a [`Result::Err`] containing an [`arc_anyhow::Error`].
///
/// Otherwise similar to [`anyhow::bail`].
#[macro_export]
macro_rules! bail {
    ($fmt:literal $(,)?) => {
        return Err($crate::anyhow!($fmt))
    };
    ($err:expr $(,)?) => {
        return Err($crate::anyhow!($err))
    };
    ($fmt:expr, $($arg:tt)*) => {
        return Err($crate::anyhow!($fmt, $($arg)*))
    };
}

/// Returns a [`Result::Err`] containing an [`arc_anyhow::Error`] if the given
/// condition evaluates to false.
///
/// Otherwise similar to [`anyhow::ensure`].
#[macro_export]
macro_rules! ensure {
    ($cond:expr, $fmt:literal $(,)?) => {
        if !$cond { bail!($fmt); }
    };
    ($cond:expr, $err:expr $(,)?) => {
        if !$cond { bail!($err); }
    };
    ($cond:expr, $fmt:expr, $($arg:tt)*) => {
        if !$cond { bail!($fmt, $($arg)*); }
    };
}

pub trait ErrorReporting: std::fmt::Debug {
    /// Inserts a new error. Uses interior mutability so that references can be
    /// shared freely.
    fn insert(&self, error: &arc_anyhow::Error);
    fn serialize_to_vec(&self) -> anyhow::Result<Vec<u8>>;
}

/// A null [`ErrorReporting`] strategy.
#[derive(Debug)]
pub struct IgnoreErrors;

impl ErrorReporting for IgnoreErrors {
    fn insert(&self, _error: &arc_anyhow::Error) {}

    fn serialize_to_vec(&self) -> anyhow::Result<Vec<u8>> {
        Ok(vec![])
    }
}

/// An aggregate of zero or more errors.
#[derive(Default, Debug)]
pub struct ErrorReport {
    // The interior mutability / borrow_mut will never panic: it is never borrowed for longer than
    // a method call, and the methods do not call each other.
    map: RefCell<BTreeMap<Cow<'static, str>, ErrorReportEntry>>,
}

impl ErrorReport {
    pub fn new() -> Self {
        Self::default()
    }
}

impl ErrorReporting for ErrorReport {
    fn insert(&self, error: &arc_anyhow::Error) {
        let root_cause = error.root_cause();
        if let Some(error) = root_cause.downcast_ref::<FormattedError>() {
            let sample_message = if error.message != error.fmt { &*error.message } else { "" };
            self.map
                .borrow_mut()
                .entry(error.fmt.clone())
                .or_default()
                .add(Cow::Borrowed(sample_message));
        } else {
            self.map
                .borrow_mut()
                .entry(Cow::Borrowed("{}"))
                .or_default()
                .add(Cow::Owned(format!("{error}")));
        }
    }

    fn serialize_to_vec(&self) -> anyhow::Result<Vec<u8>> {
        Ok(serde_json::to_vec(&*self.map.borrow())?)
    }
}

#[derive(Default, Debug, Serialize)]
struct ErrorReportEntry {
    count: u64,
    #[serde(skip_serializing_if = "String::is_empty")]
    sample_message: String,
}

impl ErrorReportEntry {
    fn add(&mut self, message: Cow<str>) {
        if self.count == 0 {
            self.sample_message = message.into_owned();
        }
        self.count += 1;
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn anyhow_1arg_static_plain() {
        let arc_err = anyhow!("abc");
        let err: &FormattedError = arc_err.downcast_ref().unwrap();
        assert!(matches!(err.fmt, Cow::Borrowed(_)));
        assert_eq!(err.fmt, "abc");
        assert!(matches!(err.message, Cow::Borrowed(_)));
        assert_eq!(err.message, "abc");
    }

    #[test]
    fn anyhow_1arg_static_fmt() {
        let some_var = "def";
        let arc_err = anyhow!("abc{some_var}");
        let err: &FormattedError = arc_err.downcast_ref().unwrap();
        assert!(matches!(err.fmt, Cow::Borrowed(_)));
        assert_eq!(err.fmt, "abc{some_var}");
        assert!(matches!(err.message, Cow::Owned(_)));
        assert_eq!(err.message, "abcdef");
    }

    #[test]
    fn anyhow_1arg_dynamic() {
        let arc_err = anyhow!(format!("abc{}", "def"));
        let err: &FormattedError = arc_err.downcast_ref().unwrap();
        assert!(matches!(err.fmt, Cow::Owned(_)));
        assert_eq!(err.fmt, "abcdef");
        assert!(matches!(err.message, Cow::Owned(_)));
        assert_eq!(err.message, "abcdef");
    }

    #[test]
    fn anyhow_2arg() {
        let arc_err = anyhow!("abc{}", "def");
        let err: &FormattedError = arc_err.downcast_ref().unwrap();
        assert!(matches!(err.fmt, Cow::Borrowed(_)));
        assert_eq!(err.fmt, "abc{}");
        assert!(matches!(err.message, Cow::Borrowed(_)));
        assert_eq!(err.message, "abcdef");
    }

    #[test]
    fn bail_1arg_static_plain() {
        let arc_err = (|| -> arc_anyhow::Result<()> { bail!("abc") })().unwrap_err();
        let err: &FormattedError = arc_err.downcast_ref().unwrap();
        assert!(matches!(err.fmt, Cow::Borrowed(_)));
        assert_eq!(err.fmt, "abc");
        assert!(matches!(err.message, Cow::Borrowed(_)));
        assert_eq!(err.message, "abc");
    }

    #[test]
    fn bail_1arg_static_fmt() {
        let some_var = "def";
        let arc_err = (|| -> arc_anyhow::Result<()> { bail!("abc{some_var}") })().unwrap_err();
        let err: &FormattedError = arc_err.downcast_ref().unwrap();
        assert!(matches!(err.fmt, Cow::Borrowed(_)));
        assert_eq!(err.fmt, "abc{some_var}");
        assert!(matches!(err.message, Cow::Owned(_)));
        assert_eq!(err.message, "abcdef");
    }

    #[test]
    fn bail_1arg_dynamic() {
        let arc_err =
            (|| -> arc_anyhow::Result<()> { bail!(format!("abc{}", "def")) })().unwrap_err();
        let err: &FormattedError = arc_err.downcast_ref().unwrap();
        assert!(matches!(err.fmt, Cow::Owned(_)));
        assert_eq!(err.fmt, "abcdef");
        assert!(matches!(err.message, Cow::Owned(_)));
        assert_eq!(err.message, "abcdef");
    }

    #[test]
    fn bail_2arg() {
        let arc_err = (|| -> arc_anyhow::Result<()> { bail!("abc{}", "def") })().unwrap_err();
        let err: &FormattedError = arc_err.downcast_ref().unwrap();
        assert!(matches!(err.fmt, Cow::Borrowed(_)));
        assert_eq!(err.fmt, "abc{}");
        assert!(matches!(err.message, Cow::Borrowed(_)));
        assert_eq!(err.message, "abcdef");
    }

    #[test]
    fn ensure_pass() {
        let f = || {
            ensure!(true, "unused message");
            Ok(())
        };
        f().unwrap();
    }

    #[test]
    fn ensure_fail_1arg_static_plain() {
        let arc_err = (|| {
            ensure!(false, "abc");
            Ok(())
        })()
        .unwrap_err();
        let err: &FormattedError = arc_err.downcast_ref().unwrap();
        assert!(matches!(err.fmt, Cow::Borrowed(_)));
        assert_eq!(err.fmt, "abc");
        assert!(matches!(err.message, Cow::Borrowed(_)));
        assert_eq!(err.message, "abc");
    }

    #[test]
    fn ensure_fail_1arg_static_fmt() {
        let some_var = "def";
        let arc_err = (|| {
            ensure!(false, "abc{some_var}");
            Ok(())
        })()
        .unwrap_err();
        let err: &FormattedError = arc_err.downcast_ref().unwrap();
        assert!(matches!(err.fmt, Cow::Borrowed(_)));
        assert_eq!(err.fmt, "abc{some_var}");
        assert!(matches!(err.message, Cow::Owned(_)));
        assert_eq!(err.message, "abcdef");
    }

    #[test]
    fn ensure_fail_1arg_dynamic() {
        let arc_err = (|| {
            ensure!(false, format!("abc{}", "def"));
            Ok(())
        })()
        .unwrap_err();
        let err: &FormattedError = arc_err.downcast_ref().unwrap();
        assert!(matches!(err.fmt, Cow::Owned(_)));
        assert_eq!(err.fmt, "abcdef");
        assert!(matches!(err.message, Cow::Owned(_)));
        assert_eq!(err.message, "abcdef");
    }

    #[test]
    fn ensure_fail_2arg() {
        let arc_err = (|| {
            ensure!(false, "abc{}", "def");
            Ok(())
        })()
        .unwrap_err();
        let err: &FormattedError = arc_err.downcast_ref().unwrap();
        assert!(matches!(err.fmt, Cow::Borrowed(_)));
        assert_eq!(err.fmt, "abc{}");
        assert!(matches!(err.message, Cow::Borrowed(_)));
        assert_eq!(err.message, "abcdef");
    }

    #[test]
    fn error_report() {
        let report = ErrorReport::new();
        report.insert(&anyhow!("abc{}", "def"));
        report.insert(&anyhow!("abc{}", "123"));
        report.insert(&anyhow!("error code: {}", 65535));
        report.insert(&anyhow!("no parameters"));
        report.insert(&anyhow!("no parameters"));
        report.insert(&anyhow!("no parameters"));
        report.insert(&anyhow::Error::msg("not attributed").into());
        report.insert(&anyhow!("has context from arc_anyhow::context()").context("the context"));
        report.insert(
            &arc_anyhow::Context::context(
                Result::<(), _>::Err(anyhow!("has context from arc_anyhow::Context::context()")),
                "the context",
            )
            .unwrap_err(),
        );
        report.insert(
            &arc_anyhow::Context::with_context(
                Result::<(), _>::Err(anyhow!(
                    "has context from arc_anyhow::Context::with_context()"
                )),
                || "the context",
            )
            .unwrap_err(),
        );
        report.insert(
            &anyhow!("has three layers of context")
                .context("context 1")
                .context("context 2")
                .context("context 3"),
        );

        assert_eq!(
            serde_json::to_string_pretty(&*report.map.borrow()).unwrap(),
            r#"{
  "abc{}": {
    "count": 2,
    "sample_message": "abcdef"
  },
  "error code: {}": {
    "count": 1,
    "sample_message": "error code: 65535"
  },
  "has context from arc_anyhow::Context::context()": {
    "count": 1
  },
  "has context from arc_anyhow::Context::with_context()": {
    "count": 1
  },
  "has context from arc_anyhow::context()": {
    "count": 1
  },
  "has three layers of context": {
    "count": 1
  },
  "no parameters": {
    "count": 3
  },
  "{}": {
    "count": 1,
    "sample_message": "not attributed"
  }
}"#,
        );
    }
}
