// SPDX-License-Identifier: Apache-2.0
//! Seed data for the mockup. No persistence; values live in memory.

/// Visibility states displayed in the album card.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Visibility {
    OwnerOnly,
    SharedByLink,
    SharedByInvitation,
    SharedByFamilyKey,
    SharedByMultiple,
    Paused,
}

impl Visibility {
    #[must_use]
    pub fn label(self) -> &'static str {
        match self {
            Self::OwnerOnly => "Only you",
            Self::SharedByLink => "Shared by private link",
            Self::SharedByInvitation => "Shared with invited viewers",
            Self::SharedByFamilyKey => "Shared with Family key",
            Self::SharedByMultiple => "Shared with selected people",
            Self::Paused => "Sharing paused",
        }
    }

    #[must_use]
    pub fn modifier(self) -> &'static str {
        match self {
            Self::OwnerOnly => "badge--slate",
            Self::SharedByLink | Self::SharedByMultiple => "badge--sage",
            Self::SharedByInvitation => "badge--sage",
            Self::SharedByFamilyKey => "badge--sage",
            Self::Paused => "badge--amber",
        }
    }
}

#[derive(Clone, Debug, PartialEq)]
pub struct Album {
    pub id: String,
    pub title: String,
    pub photo_count: usize,
    pub visibility: Visibility,
    pub updated_at: String,
    pub cover_palette: (String, String),
    /// True for albums shared with the current user by someone else.
    /// False (default) for albums the user owns.
    pub is_received: bool,
    /// Name of the person who shared the album, if `is_received`.
    pub received_from: Option<String>,
}

#[derive(Clone, Debug, PartialEq)]
pub struct Photo {
    pub id: String,
    pub album_id: String,
    pub captured_at: Option<String>,
    pub uploaded_at: String,
    pub cleaning_level: String,
    pub has_location: bool,
    pub has_device_info: bool,
    pub palette: (String, String),
}

/// Pre-populated albums for the mockup.
#[must_use]
pub fn seed_albums() -> Vec<Album> {
    // Macro to reduce repetition for owned albums
    macro_rules! owned {
        ($id:expr, $title:expr, $count:expr, $vis:expr, $age:expr, $c0:expr, $c1:expr) => {
            Album {
                id: $id.into(),
                title: $title.into(),
                photo_count: $count,
                visibility: $vis,
                updated_at: $age.into(),
                cover_palette: ($c0.into(), $c1.into()),
                is_received: false,
                received_from: None,
            }
        };
    }
    macro_rules! received {
        ($id:expr, $title:expr, $count:expr, $from:expr, $age:expr, $c0:expr, $c1:expr) => {
            Album {
                id: $id.into(),
                title: $title.into(),
                photo_count: $count,
                visibility: Visibility::SharedByInvitation,
                updated_at: $age.into(),
                cover_palette: ($c0.into(), $c1.into()),
                is_received: true,
                received_from: Some($from.into()),
            }
        };
    }

    vec![
        // ── Owned albums ─────────────────────────────────────────────────────
        owned!(
            "alb_summer",
            "Summer at home",
            42,
            Visibility::SharedByFamilyKey,
            "2 days ago",
            "#c4a574",
            "#8a6a3f"
        ),
        owned!(
            "alb_birthday",
            "Mira's first birthday",
            87,
            Visibility::SharedByLink,
            "Last week",
            "#d4a8a3",
            "#9a5e58"
        ),
        owned!(
            "alb_walks",
            "Morning walks",
            23,
            Visibility::OwnerOnly,
            "3 days ago",
            "#a8b8a4",
            "#6a8462"
        ),
        owned!(
            "alb_kyoto",
            "Kyoto, late autumn",
            134,
            Visibility::SharedByInvitation,
            "Last month",
            "#c4856a",
            "#7a4a3a"
        ),
        owned!(
            "alb_quiet",
            "Quiet things",
            18,
            Visibility::OwnerOnly,
            "Yesterday",
            "#b8b3a8",
            "#7d796f"
        ),
        owned!(
            "alb_grand",
            "With Grandma",
            56,
            Visibility::Paused,
            "2 weeks ago",
            "#c8b890",
            "#8a7a5a"
        ),
        // ── Received albums (shared with the current user by others) ─────────
        received!(
            "alb_shared_hana",
            "Hana's first birthday",
            34,
            "Sarah",
            "2 hours ago",
            "#d4a8a3",
            "#9a5e58"
        ),
        received!(
            "alb_shared_game",
            "Game vs Lions — Oct 14",
            47,
            "Coach Tom",
            "3 days ago",
            "#a8b8d4",
            "#4a5e8a"
        ),
        received!(
            "alb_shared_wedding",
            "Mira & Kenji — June 2024",
            312,
            "Marcus",
            "Jun 2024",
            "#c4b8a8",
            "#887860"
        ),
        received!(
            "alb_shared_trip",
            "Autumn in Nara",
            88,
            "Yuki",
            "Yesterday",
            "#b8a898",
            "#7a6858"
        ),
    ]
}

/// Pre-populated photos.
#[must_use]
pub fn seed_photos() -> Vec<Photo> {
    let palettes = [
        ("#c4a574", "#8a6a3f"),
        ("#d4a8a3", "#9a5e58"),
        ("#a8b8a4", "#6a8462"),
        ("#c4856a", "#7a4a3a"),
        ("#b8b3a8", "#7d796f"),
        ("#c8b890", "#8a7a5a"),
        ("#a3a8b8", "#5e6580"),
        ("#d4c08c", "#a08850"),
        ("#9aa898", "#5a6a58"),
        ("#cda897", "#8a6855"),
        ("#b8a3a8", "#7a5e65"),
        ("#a8c0bc", "#608078"),
    ];
    let album_ids = ["alb_summer", "alb_birthday", "alb_walks", "alb_kyoto"];
    let levels = ["privacy", "standard", "detailed"];

    let mut photos = Vec::with_capacity(48);
    for i in 0..48 {
        let p = palettes[i % palettes.len()];
        photos.push(Photo {
            id: format!("photo_{i:03}"),
            album_id: album_ids[i % album_ids.len()].to_string(),
            captured_at: if i % 5 == 0 {
                None
            } else {
                Some(format!("Aug {}, 2025", (i % 28) + 1))
            },
            uploaded_at: format!("Sep {}, 2025", (i % 28) + 1),
            cleaning_level: levels[i % levels.len()].to_string(),
            has_location: i % 6 == 0,
            has_device_info: false,
            palette: (p.0.to_string(), p.1.to_string()),
        });
    }
    photos
}

// ── Shared-with-me inbox ─────────────────────────────────────────────────────

/// An album that someone else shared with the current user.
#[derive(Clone, Debug, PartialEq)]
pub struct SharedWithMe {
    pub id: &'static str,
    pub album_id: &'static str,
    pub album_title: &'static str,
    pub sender_name: &'static str,
    pub photo_count: usize,
    pub new_count: usize, // photos added since last view
    pub shared_at: &'static str,
    pub expires_at: Option<&'static str>,
    pub cover_palette: (&'static str, &'static str),
}

pub fn seed_shared_with_me() -> Vec<SharedWithMe> {
    vec![
        SharedWithMe {
            id: "swm_001",
            album_id: "alb_shared_hana",
            album_title: "Hana's first birthday",
            sender_name: "Sarah",
            photo_count: 34,
            new_count: 12,
            shared_at: "2 hours ago",
            expires_at: None,
            cover_palette: ("#d4a8a3", "#9a5e58"),
        },
        SharedWithMe {
            id: "swm_002",
            album_id: "alb_shared_game",
            album_title: "Game vs Lions — Oct 14",
            sender_name: "Coach Tom",
            photo_count: 47,
            new_count: 0,
            shared_at: "3 days ago",
            expires_at: Some("Dec 31, 2025"),
            cover_palette: ("#a8b8d4", "#4a5e8a"),
        },
        SharedWithMe {
            id: "swm_003",
            album_id: "alb_shared_wedding",
            album_title: "Mira & Kenji — June 2024",
            sender_name: "Marcus",
            photo_count: 312,
            new_count: 0,
            shared_at: "Jun 15, 2024",
            expires_at: Some("Jun 15, 2025"),
            cover_palette: ("#c4b8a8", "#887860"),
        },
        SharedWithMe {
            id: "swm_004",
            album_id: "alb_shared_trip",
            album_title: "Autumn in Nara",
            sender_name: "Yuki",
            photo_count: 88,
            new_count: 5,
            shared_at: "Yesterday",
            expires_at: None,
            cover_palette: ("#b8a898", "#7a6858"),
        },
    ]
}

// ── Sharing overview ─────────────────────────────────────────────────────────

#[derive(Clone, Debug, PartialEq)]
pub struct ActiveShare {
    pub id: &'static str,
    pub kind: ShareKind,
    pub label: &'static str,
    pub albums: &'static [&'static str], // album titles
    pub scope_summary: &'static str,     // "3 albums" or "Family · 4 members"
    pub status_note: &'static str,       // "Expires Aug 30" / "Auto-share on"
    pub is_active: bool,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ShareKind {
    PrivateLink,
    FamilyKey,
    Invitation,
}

pub fn seed_active_shares() -> Vec<ActiveShare> {
    vec![
        ActiveShare {
            id: "sh_family",
            kind: ShareKind::FamilyKey,
            label: "Family key — \"Family\"",
            albums: &["Hana's first year", "Sunday lunches", "Morning walks"],
            scope_summary: "3 albums · 4 members",
            status_note: "Auto-share new photos: on",
            is_active: true,
        },
        ActiveShare {
            id: "sh_link_gp",
            kind: ShareKind::PrivateLink,
            label: "Private link — Grandparents",
            albums: &["Kyoto, late autumn"],
            scope_summary: "1 album · password protected",
            status_note: "Expires Aug 30, 2025",
            is_active: true,
        },
        ActiveShare {
            id: "sh_link_wed",
            kind: ShareKind::PrivateLink,
            label: "Private link — Wedding guests",
            albums: &["Mira's first birthday"],
            scope_summary: "1 album · downloads allowed",
            status_note: "No expiry",
            is_active: true,
        },
        ActiveShare {
            id: "sh_inv_marcus",
            kind: ShareKind::Invitation,
            label: "Invitation — marcus@example.org",
            albums: &["Summer at home"],
            scope_summary: "1 album",
            status_note: "Accepted · viewer",
            is_active: true,
        },
        ActiveShare {
            id: "sh_inv_tom",
            kind: ShareKind::Invitation,
            label: "Invitation — tom@example.org",
            albums: &["Morning walks"],
            scope_summary: "1 album",
            status_note: "Expired Apr 14, 2025",
            is_active: false,
        },
    ]
}
