# RailsSettings Model
class Setting < RailsSettings::Base
  cache_prefix { "v1" }

  field :primary_domain, type: :string,
    default: ENV["PRIMARY_DOMAIN"].presence

  field :accounts_domain, type: :string,
    default: ENV["AKKOUNTS_DOMAIN"].presence

  #
  # Internal services
  #

  field :redis_url, type: :string,
    default: ENV["REDIS_URL"] || "redis://localhost:6379/0"

  #
  # Registrations
  #

  field :reserved_usernames, type: :array, default: %w[
    account accounts donations mail webmaster support
  ]

  #
  # XMPP
  #

  field :xmpp_default_rooms, type: :array, default: []
  field :xmpp_autojoin_default_rooms, type: :boolean, default: false
  field :xmpp_notifications_from_address, type: :string, default: primary_domain

  #
  # Sentry
  #

  field :sentry_enabled, type: :boolean, readonly: true,
    default: ENV["SENTRY_DSN"].present?

  #
  # BTCPay Server
  #

  field :btcpay_api_url, type: :string,
    default: ENV["BTCPAY_API_URL"].presence

  field :btcpay_enabled, type: :boolean,
    default: ENV["BTCPAY_API_URL"].present?

  field :btcpay_store_id, type: :string,
    default: ENV["BTCPAY_STORE_ID"].presence

  field :btcpay_auth_token, type: :string,
    default: ENV["BTCPAY_AUTH_TOKEN"].presence

  field :btcpay_publish_wallet_balances, type: :boolean, default: true

  #
  # Discourse
  #

  field :discourse_public_url, type: :string,
    default: ENV["DISCOURSE_PUBLIC_URL"].presence

  field :discourse_enabled, type: :boolean,
    default: ENV["DISCOURSE_PUBLIC_URL"].present?

  field :discourse_connect_secret, type: :string,
    default: ENV["DISCOURSE_CONNECT_SECRET"].presence

  #
  # Drone CI
  #

  field :droneci_public_url, type: :string,
    default: ENV["DRONECI_PUBLIC_URL"].presence

  field :droneci_enabled, type: :boolean,
    default: ENV["DRONECI_PUBLIC_URL"].present?

  #
  # ejabberd
  #

  field :ejabberd_enabled, type: :boolean,
    default: ENV["EJABBERD_API_URL"].present?

  field :ejabberd_api_url, type: :string,
    default: ENV["EJABBERD_API_URL"].presence

  field :ejabberd_admin_url, type: :string,
    default: ENV["EJABBERD_ADMIN_URL"].presence

  field :ejabberd_buddy_roster, type: :string,
    default: "Buddies"

  #
  # Gitea
  #

  field :gitea_public_url, type: :string,
    default: ENV["GITEA_PUBLIC_URL"].presence

  field :gitea_enabled, type: :boolean,
    default: ENV["GITEA_PUBLIC_URL"].present?

  #
  # Lightning Network
  #

  field :lndhub_api_url, type: :string,
    default: ENV["LNDHUB_API_URL"].presence

  field :lndhub_enabled, type: :boolean,
    default: ENV["LNDHUB_API_URL"].present?

  field :lndhub_admin_token, type: :string,
    default: ENV["LNDHUB_ADMIN_TOKEN"].presence

  field :lndhub_admin_enabled, type: :boolean,
    default: ENV["LNDHUB_ADMIN_UI"] || false

  field :lndhub_public_key, type: :string,
    default: (ENV["LNDHUB_PUBLIC_KEY"] || "")

  field :lndhub_keysend_enabled, type: :boolean,
    default: -> { self.lndhub_public_key.present? }

  #
  # Mastodon
  #

  field :mastodon_public_url, type: :string,
    default: ENV["MASTODON_PUBLIC_URL"].presence

  field :mastodon_enabled, type: :boolean,
    default: ENV["MASTODON_PUBLIC_URL"].present?

  field :mastodon_address_domain, type: :string,
    default: ENV["MASTODON_ADDRESS_DOMAIN"].presence || self.primary_domain

  #
  # MediaWiki
  #

  field :mediawiki_public_url, type: :string,
    default: ENV["MEDIAWIKI_PUBLIC_URL"].presence

  field :mediawiki_enabled, type: :boolean,
    default: ENV["MEDIAWIKI_PUBLIC_URL"].present?

  #
  # Nostr
  #

  field :nostr_enabled, type: :boolean, default: true

  #
  # RemoteStorage
  #

  field :remotestorage_enabled, type: :boolean,
    default: ENV["RS_STORAGE_URL"].present?

  field :rs_storage_url, type: :string,
    default: ENV["RS_STORAGE_URL"].presence

  field :rs_redis_url, type: :string,
    default: ENV["RS_REDIS_URL"] || "redis://localhost:6379/1"


  #
  # E-Mail Service
  #

  field :email_enabled, type: :boolean,
    default: ENV["EMAIL_SMTP_HOST"].present?

  # field :email_smtp_host, type: :string,
  #   default: ENV["EMAIL_SMTP_HOST"].presence
  #
  # field :email_smtp_port, type: :string,
  #   default: ENV["EMAIL_SMTP_PORT"].presence || 587
  #
  # field :email_smtp_enable_starttls, type: :string,
  #   default: ENV["EMAIL_SMTP_PORT"].presence || true
  #
  # field :email_auth_method, type: :string,
  #   default: ENV["EMAIL_AUTH_METHOD"].presence || "plain"
  #
  # field :email_imap_host, type: :string,
  #   default: ENV["EMAIL_IMAP_HOST"].presence
  #
  # field :email_imap_port, type: :string,
  #   default: ENV["EMAIL_IMAP_PORT"].presence || 993
end
