//! Input query models for site resource discovery and future subtitle matching.

use crate::types::{ExternalIds, Pagination};

/// A normalized query for primary media resource discovery.
#[derive(Debug, Clone)]
pub struct MediaResourceQuery {
    /// Search target kind used by site providers.
    pub media_type: MediaQueryMediaType,
    /// Canonical title used for discovery.
    pub title: String,
    /// Optional original title when a site indexes foreign titles separately.
    pub original_title: Option<String>,
    /// Optional release year.
    pub year: Option<i32>,
    /// Optional season number when searching episodic content.
    pub season: Option<i32>,
    /// Optional episode number when searching episodic content.
    pub episode: Option<i32>,
    /// Shared external identifiers for higher-confidence lookup.
    pub external_ids: ExternalIds,
    /// Site/domain-specific category hints.
    pub categories: Vec<String>,
    /// Free-form keywords for provider-side query adaptation.
    pub keywords: Vec<String>,
    /// Optional technical filters for resource search.
    pub release_filters: ReleaseFilters,
    /// Shared pagination primitive.
    pub pagination: Pagination,
}

/// Search semantics for primary resource discovery.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MediaQueryMediaType {
    /// Search for a movie.
    Movie,
    /// Search for a single episode.
    Episode,
    /// Search for a season pack.
    SeasonPack,
    /// Search for anime content.
    Anime,
    /// The caller cannot classify the search target.
    Unknown,
}

/// Technical filters applied during resource discovery.
#[derive(Debug, Clone, Default)]
pub struct ReleaseFilters {
    /// Allowed resolutions such as `1080p` or `2160p`.
    pub resolutions: Vec<String>,
    /// Allowed sources such as `bluray`, `web-dl`, or `hdtv`.
    pub sources: Vec<String>,
    /// Allowed codecs such as `x264`, `x265`, or `av1`.
    pub codecs: Vec<String>,
    /// Preferred or required release groups.
    pub release_groups: Vec<String>,
}

/// A planned subtitle matching query.
#[derive(Debug, Clone)]
pub struct SubtitleQuery {
    /// Subtitle matching target kind.
    pub media_type: SubtitleQueryMediaType,
    /// Canonical title used for subtitle matching.
    pub title: String,
    /// Optional original title when subtitle providers index it separately.
    pub original_title: Option<String>,
    /// Optional release year.
    pub year: Option<i32>,
    /// Optional season number.
    pub season: Option<i32>,
    /// Optional episode number.
    pub episode: Option<i32>,
    /// Shared external identifiers for stronger matching.
    pub external_ids: ExternalIds,
    /// Preferred subtitle languages.
    pub language_preferences: Vec<String>,
    /// Optional local file context for strong matching.
    pub local_file: Option<LocalFileContext>,
    /// Optional resource context when subtitles are matched around a known
    /// resource.
    pub source_resource: Option<ResourceContext>,
    /// Optional release-level hints.
    pub release_context: Option<ReleaseContext>,
}

/// Search semantics for subtitle matching.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SubtitleQueryMediaType {
    /// Match subtitles for a movie.
    Movie,
    /// Match subtitles for an episode.
    Episode,
    /// The caller cannot classify the subtitle target.
    Unknown,
}

/// Local file context used to improve subtitle matching.
#[derive(Debug, Clone, Default)]
pub struct LocalFileContext {
    /// Absolute or provider-relevant file path.
    pub path: String,
    /// Optional file size in bytes.
    pub size: Option<u64>,
    /// Optional file hash hint.
    pub hash_hint: Option<String>,
    /// Optional release name derived from the local file.
    pub release_name: Option<String>,
}

/// Context describing the primary resource around which subtitle matching
/// happens.
#[derive(Debug, Clone)]
pub struct ResourceContext {
    /// Provider that produced the resource.
    pub provider: String,
    pub resource_key: String,
    /// Display title of the resource.
    pub title: String,
}

/// Release-level hints used during subtitle matching.
#[derive(Debug, Clone, Default)]
pub struct ReleaseContext {
    /// Optional source such as `bluray` or `web-dl`.
    pub source: Option<String>,
    /// Optional resolution such as `1080p`.
    pub resolution: Option<String>,
    /// Optional codec such as `x264` or `x265`.
    pub codec: Option<String>,
    /// Optional release group.
    pub release_group: Option<String>,
}
