use chrono::{DateTime, Utc};

pub struct NewMovie {
    pub library_id: i64,
    pub title: String,
    pub file: String,
    pub release_year: Option<i32>,
}

#[allow(dead_code)]
#[derive(Debug, myplayer_derive::FromRow)]
pub struct Movie {
    pub id: i64,
    pub library_id: i64,
    pub tmdb_id: Option<i64>,
    pub title: String,
    pub original_title: Option<String>,
    pub release_year: Option<i64>,
    pub file: String,
    pub description: Option<String>,
    pub rating: Option<f64>,
    pub watched: bool,
    pub skip_auto_match: bool,
    pub playback_position: Option<f64>,
    pub last_playback: Option<DateTime<Utc>>,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}

#[derive(myplayer_derive::FromRow)]
pub struct HostEntry {
    #[allow(dead_code)]
    pub key: String,
    pub value: String,
}

#[allow(dead_code)]
#[derive(myplayer_derive::FromRow)]
pub struct ImageRow {
    pub id: i64,
    pub image: Vec<u8>,
    pub filename: String,
    pub mime_type: String,
    pub size: i64,
}

#[derive(myplayer_derive::FromRow)]
pub struct MovieWithCover {
    pub id: i64,
    pub tmdb_id: Option<i64>,
    pub title: String,
    pub original_title: Option<String>,
    pub release_year: Option<i64>,
    pub file: String,
    pub library_root_path: String,
    pub cover_filename: Option<String>,
    pub backdrop_filename: Option<String>,
    pub description: Option<String>,
    pub rating: Option<f64>,
    pub watched: bool,
    pub playback_position: Option<f64>,
}

#[derive(myplayer_derive::FromRow)]
pub struct ShowWithCover {
    pub id: i64,
    pub tmdb_id: Option<i64>,
    pub title: String,
    pub original_title: Option<String>,
    pub release_year: Option<i64>,
    pub cover_filename: Option<String>,
    pub backdrop_filename: Option<String>,
    pub description: Option<String>,
    pub rating: Option<f64>,
    pub watched: bool,
}

#[allow(dead_code)]
#[derive(myplayer_derive::FromRow)]
pub struct SeasonWithCover {
    pub id: i64,
    pub show_id: i64,
    pub tmdb_id: Option<i64>,
    pub season_number: i64,
    pub title: Option<String>,
    pub release_year: Option<i64>,
    pub cover_filename: Option<String>,
    pub description: Option<String>,
    pub rating: Option<f64>,
    pub watched: bool,
}

pub struct NewShow {
    pub title: String,
}

#[allow(dead_code)]
#[derive(myplayer_derive::FromRow)]
pub struct Show {
    pub id: i64,
    pub tmdb_id: Option<i64>,
    pub title: String,
    pub original_title: Option<String>,
    pub release_year: Option<i64>,
    pub description: Option<String>,
    pub rating: Option<f64>,
    pub watched: bool,
    pub skip_auto_match: bool,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}

#[allow(dead_code)]
impl Show {
    pub fn title(&self) -> String {
        self.original_title
            .as_ref()
            .unwrap_or(&self.title)
            .to_string()
    }
}

pub struct NewSeason {
    pub show_id: i64,
    pub season_number: i64,
}

#[allow(dead_code)]
#[derive(myplayer_derive::FromRow)]
pub struct Season {
    pub id: i64,
    pub show_id: i64,
    pub tmdb_id: Option<i64>,
    pub season_number: i64,
    pub title: Option<String>,
    pub release_year: Option<i64>,
    pub description: Option<String>,
    pub rating: Option<f64>,
    pub watched: bool,
    pub skip_auto_match: bool,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}

pub struct NewEpisode {
    pub season_id: i64,
    pub library_id: i64,
    pub episode_number: i64,
    pub file: String,
}

#[allow(dead_code)]
#[derive(myplayer_derive::FromRow)]
pub struct Episode {
    pub id: i64,
    pub season_id: i64,
    pub library_id: i64,
    pub tmdb_id: Option<i64>,
    pub episode_number: i64,
    pub title: Option<String>,
    pub file: String,
    pub watched: bool,
    pub playback_position: Option<f64>,
    pub last_playback: Option<DateTime<Utc>>,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}

#[derive(myplayer_derive::FromRow)]
pub struct EpisodeWithLibrary {
    pub id: i64,
    pub episode_number: i64,
    pub title: Option<String>,
    pub file: String,
    pub library_root_path: String,
    pub watched: bool,
    pub playback_position: Option<f64>,
}

#[allow(dead_code)]
#[derive(myplayer_derive::FromRow)]
pub struct Library {
    pub id: i64,
    pub name: String,
    pub root_path: String,
    pub media_type: String,
    pub created_at: DateTime<Utc>,
}

#[derive(myplayer_derive::FromRow)]
pub struct FileRow {
    pub file: String,
}

#[derive(myplayer_derive::FromRow)]
pub struct IdRow {
    pub id: i64,
}

#[allow(dead_code)]
#[derive(myplayer_derive::FromRow)]
pub struct RecentSeasonWithCover {
    pub id: i64,
    pub show_id: i64,
    pub season_number: i64,
    pub title: Option<String>,
    pub show_title: String,
    pub cover_filename: Option<String>,
    pub watched: bool,
}

#[derive(myplayer_derive::FromRow)]
pub struct UnmatchedSeason {
    pub id: i64,
    pub show_id: i64,
    pub season_number: i64,
    pub show_tmdb_id: i64,
    pub show_title: String,
}

#[allow(dead_code)]
#[derive(myplayer_derive::FromRow)]
pub struct MediaMeta {
    pub id: i64,
    pub file: String,
    pub duration: f64,
    pub created_at: DateTime<Utc>,
}

#[derive(myplayer_derive::FromRow)]
pub struct ContinueWatchingMovie {
    pub id: i64,
    pub title: String,
    pub original_title: Option<String>,
    pub file: String,
    pub library_root_path: String,
    pub backdrop_filename: Option<String>,
    pub playback_position: f64,
    pub duration: Option<f64>,
    pub last_playback: DateTime<Utc>,
}

#[allow(dead_code)]
#[derive(myplayer_derive::FromRow)]
pub struct ContinueWatchingEpisode {
    pub id: i64,
    pub episode_number: i64,
    pub title: Option<String>,
    pub file: String,
    pub library_root_path: String,
    pub show_id: i64,
    pub show_title: String,
    pub season_id: i64,
    pub season_number: i64,
    pub backdrop_filename: Option<String>,
    pub playback_position: f64,
    pub duration: Option<f64>,
    pub last_playback: DateTime<Utc>,
}
