// Copyright (C) 2026 Ordinary Labs, LLC.
//
// SPDX-License-Identifier: AGPL-3.0-only

use serde::{Deserialize, Serialize};

#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[cfg_attr(feature = "docs", derive(schemars::JsonSchema))]
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct AssetsLimits {
    /// Allowed extensions corresponding to
    /// [MIME](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types) types.
    ///
    /// (More to be supported in the future)
    ///
    /// Supported:
    /// - "txt"
    /// - "xml"
    /// - "html"
    /// - "css"
    /// - "css.map"
    /// - "csv"
    /// - "js"
    /// - "png"
    /// - "apng"
    /// - "gif"
    /// - "svg"
    /// - "jpg"
    /// - "jpeg"
    /// - "bmp"
    /// - "tif"
    /// - "tiff"
    /// - "webp"
    /// - "avif"
    /// - "ico"
    /// - "pdf"
    /// - "json"
    /// - "wasm"
    ///
    /// Special:
    /// - "none" (for no extension; uses "application/octet-stream")
    /// - "any" (for unsupported extensions; also uses "application/octet-stream")
    pub allowed_extensions: Vec<String>,
    /// Limit on total storage for all assets within an app
    /// (bytes).
    pub max_store_size: u64,
    /// Limit on individual asset size (bytes).
    pub max_asset_size: u64,
}

impl Default for AssetsLimits {
    fn default() -> Self {
        Self {
            allowed_extensions: vec![
                "otf".into(),
                "ttf".into(),
                "woff".into(),
                "woff2".into(),
                "txt".into(),
                "xml".into(),
                "html".into(),
                "css".into(),
                "css.map".into(),
                "csv".into(),
                "js".into(),
                "png".into(),
                "apng".into(),
                "gif".into(),
                "svg".into(),
                "jpg".into(),
                "jpeg".into(),
                "bmp".into(),
                "tif".into(),
                "tiff".into(),
                "webp".into(),
                "avif".into(),
                "ico".into(),
                "pdf".into(),
                "json".into(),
                "wasm".into(),
            ],
            max_store_size: 100_000_000,
            max_asset_size: 1_500_000,
        }
    }
}
