///|
/// Static provider capability description.
pub(all) struct ProviderCapability {
  provider : HookProvider
  supports_signature : Bool
  supports_delivery_id : Bool
  supports_retry : Bool
  common_events : Array[String]
} derive(Eq, Debug)

///|
/// Construct a provider capability profile.
pub fn ProviderCapability::ProviderCapability(
  provider : HookProvider,
  supports_signature? : Bool = true,
  supports_delivery_id? : Bool = true,
  supports_retry? : Bool = true,
  common_events? : ArrayView[String] = [],
) -> ProviderCapability {
  {
    provider,
    supports_signature,
    supports_delivery_id,
    supports_retry,
    common_events: common_events.to_owned(),
  }
}

///|
/// GitHub capability profile.
pub fn github_capability() -> ProviderCapability {
  ProviderCapability(GitHub, common_events=[
    "push", "pull_request", "issues", "issue_comment", "release", "workflow_run",
  ])
}

///|
/// GitLab capability profile.
pub fn gitlab_capability() -> ProviderCapability {
  ProviderCapability(GitLab, common_events=[
    "push", "merge_request", "issue", "note", "pipeline", "job",
  ])
}

///|
/// Gitee capability profile.
pub fn gitee_capability() -> ProviderCapability {
  ProviderCapability(Gitee, common_events=[
    "push", "pull_request", "issue", "note", "release",
  ])
}

///|
/// Feishu capability profile.
pub fn feishu_capability() -> ProviderCapability {
  ProviderCapability(Feishu, common_events=[
    "message", "interactive", "approval", "calendar", "drive",
  ])
}

///|
/// WeCom capability profile.
pub fn wecom_capability() -> ProviderCapability {
  ProviderCapability(WeCom, common_events=[
    "message", "approval", "external_contact", "kf_message",
  ])
}

///|
/// Stripe capability profile.
pub fn stripe_capability() -> ProviderCapability {
  ProviderCapability(Stripe, common_events=[
    "payment_intent.succeeded", "payment_intent.payment_failed", "checkout.session.completed",
    "invoice.paid", "customer.created",
  ])
}

///|
/// All built-in provider capability profiles.
pub fn builtin_capabilities() -> Array[ProviderCapability] {
  [
    github_capability(),
    gitlab_capability(),
    gitee_capability(),
    feishu_capability(),
    wecom_capability(),
    stripe_capability(),
  ]
}

///|
/// Find a capability by provider.
pub fn find_capability(provider : HookProvider) -> ProviderCapability? {
  for capability in builtin_capabilities() {
    if capability.provider == provider {
      return Some(capability)
    }
  }
  None
}