/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2026 metamuffin <metamuffin.org>
*/
use crate::user::{NodeUserData, User};
use std::{collections::BTreeMap, sync::Arc, time::Duration};

pub struct ApiNodeResponse {
    pub parents: NodesWithUdata,
    pub children: NodesWithUdata,
    pub node: Arc<Node>,
    pub userdata: NodeUserData,
}

pub struct ApiSearchResponse {
    pub count: usize,
    pub results: NodesWithUdata,
    pub duration: Duration,
}

pub struct ApiItemsResponse {
    pub count: usize,
    pub pages: usize,
    pub items: NodesWithUdata,
}

pub struct ApiHomeResponse {
    pub toplevel: NodesWithUdata,
    pub categories: Vec<(String, NodesWithUdata)>,
}

pub struct ApiStatsResponse {
    pub kinds: BTreeMap<NodeKind, StatsBin>,
    pub total: StatsBin,
}

pub struct ApiAdminUsersResponse {
    pub users: Vec<User>,
}

pub struct LogLine {
    pub time: DateTime<Utc>,
    pub module: Option<&'static str>,
    pub level: LogLevel,
    pub message: String,
}

url_enum!(
    #[derive(Serialize, Deserialize, Clone, Copy, PartialEq)]
    enum LogLevel {
        Trace = "trace",
        Debug = "debug",
        Info = "info",
        Warn = "warn",
        Error = "error",
    }
);

#[derive(Default, Serialize, Deserialize)]
pub struct StatsBin {
    pub runtime: f64,
    pub size: u64,
    pub count: usize,
    pub max_runtime: f64,
    pub max_runtime_node: String,
    pub max_size: u64,
    pub max_size_node: String,
}

#[derive(Debug, Default, Clone)]
pub struct NodeFilterSort {
    pub sort_by: Option<SortProperty>,
    pub filter_kind: Option<Vec<FilterProperty>>,
    pub sort_order: Option<SortOrder>,
}

url_enum!(
    #[derive(Debug, Clone, Copy, PartialEq, Eq)]
    enum FilterProperty {
        FederationLocal = "fed_local",
        FederationRemote = "fed_remote",
        Watched = "watched",
        Unwatched = "unwatched",
        WatchProgress = "watch_progress",
        KindMovie = "kind_movie",
        KindVideo = "kind_video",
        KindShortFormVideo = "kind_short_form_video",
        KindMusic = "kind_music",
        KindCollection = "kind_collection",
        KindChannel = "kind_channel",
        KindShow = "kind_show",
        KindSeries = "kind_series",
        KindSeason = "kind_season",
        KindEpisode = "kind_episode",
    }
);
url_enum!(
    #[derive(Debug, Clone, Copy, PartialEq, Eq)]
    enum SortProperty {
        ReleaseDate = "release_date",
        Title = "title",
        Index = "index",
        Duration = "duration",
        RatingRottenTomatoes = "rating_rt",
        RatingMetacritic = "rating_mc",
        RatingImdb = "rating_imdb",
        RatingTmdb = "rating_tmdb",
        RatingYoutubeViews = "rating_yt_views",
        RatingYoutubeLikes = "rating_yt_likes",
        RatingYoutubeFollowers = "rating_yt_followers",
        RatingUser = "rating_user",
        RatingLikesDivViews = "rating_loved",
    }
);
url_enum!(
    #[derive(Debug, Clone, Copy, PartialEq, Eq)]
    enum SortOrder {
        Ascending = "ascending",
        Descending = "descending",
    }
);
