use super::MessageContext;
use trigger_codegen::handlers;

#[handlers]
mod client_systems_module {
    use std::{collections::HashMap, sync::LazyLock};

    use tracing::debug;

    pub async fn on_video_get_info(
        _context: &mut MessageContext<'_, '_>,
        _request: VideoGetInfoCsReq,
    ) -> VideoGetInfoScRsp {
        static VIDEO_KEY_MAP: LazyLock<HashMap<u32, u64>> = LazyLock::new(|| {
            HashMap::from([
                // :fuckhadros:
                (1912, 13695153719640560754),
                (1913, 11970446467873604865),
                (1935, 6715089737967974053),
                (1939, 5761919859743220240),
                (1956, 12584111665037904337),
                (1957, 15837139038394391441),
                (1995, 16391754372212558964),
                (2002, 17270844273765291477),
                (2003, 9905690280726313590),
                (2004, 3759119534456498448),
                (2005, 3248379118534761865),
                (2006, 9592376511847048146),
                (2007, 9509362450087862802),
                (2008, 13966076626501039876),
                (2009, 4025058799202303972),
                (2010, 16767447703786461695),
                (2011, 9622544312867189962),
                (2012, 16671631431687028222),
                (2013, 11642245475407924993),
                (2014, 13095202570042875022),
                (2015, 4487426789754462389),
                (2016, 3212494791061893861),
                (2017, 5764063626698715038),
                (2018, 151430537129051348),
                (2019, 3183738145538588200),
                (2020, 9972804273225767699),
                (2021, 14668698147686528632),
                (2022, 18341236392667283622),
                (2023, 16706797943835517120),
                (2024, 7702082157210017817),
                (2025, 16165165268899532077),
                (2026, 10682479509529390700),
                (2027, 2609238463211199904),
                (2028, 18044895468670469236),
                (2029, 9877163830965606584),
                (2030, 10792674194514751961),
                (2031, 9366060259051599738),
                (2032, 11703514108841604904),
                (2033, 7446957309992198316),
                (2034, 14757270722441651816),
                (2035, 2716215543304086787),
                (2036, 12684775474705588717),
                (2037, 18207071206462696691),
                (2038, 17196185392823464775),
                (2039, 12170174371133024155),
                (2040, 236620601702092750),
                (2041, 11974722795993157026),
                (2042, 8789674141421997749),
                (2043, 5342884872304303352),
                (2044, 6345346740524701555),
                (2045, 16364486569280584188),
                (2046, 15605156713624712851),
                (2047, 16854800763154074100),
                (2048, 11540079199990389812),
                (2049, 4106633644530085427),
                (2050, 3809553693193430528),
            ])
        });

        VideoGetInfoScRsp {
            retcode: 0,
            video_key_map: VIDEO_KEY_MAP.clone(),
        }
    }

    pub async fn on_save_player_system_setting(
        _context: &mut MessageContext<'_, '_>,
        _request: SavePlayerSystemSettingCsReq,
    ) -> SavePlayerSystemSettingScRsp {
        SavePlayerSystemSettingScRsp { retcode: 0 }
    }

    pub async fn on_player_operation(
        _context: &mut MessageContext<'_, '_>,
        _request: PlayerOperationCsReq,
    ) -> PlayerOperationScRsp {
        PlayerOperationScRsp { retcode: 0 }
    }

    pub async fn on_get_system_settings(
        _context: &mut MessageContext<'_, '_>,
        request: GetSystemSettingsCsReq,
    ) -> GetSystemSettingsScRsp {
        GetSystemSettingsScRsp {
            retcode: 0,
            r#type: request.r#type,
            settings: Some(SystemSettings {
                systems: Vec::new(),
                switch_of_qte: false,
                switch_of_story_mode: false,
            }),
            player_settings_map: HashMap::new(),
        }
    }

    pub async fn on_get_unlock_data(
        context: &mut MessageContext<'_, '_>,
        _request: GetUnlockDataCsReq,
    ) -> GetUnlockDataScRsp {
        GetUnlockDataScRsp {
            retcode: 0,
            data: Some(UnlockData {
                unlock: Some(UnlockInfo {
                    unlocked_list: context
                        .state
                        .filecfg
                        .unlock_config_template_tb()
                        .data()
                        .unwrap()
                        .iter()
                        .map(|tmpl| tmpl.id())
                        .collect(),
                    ..Default::default()
                }),
                post_girl: Some(PostGirlInfo {
                    post_girl_item_list: context
                        .state
                        .filecfg
                        .post_girl_config_template_tb()
                        .data()
                        .unwrap()
                        .iter()
                        .map(|tmpl| PostGirlItem {
                            id: tmpl.id() as u32,
                            unlock_time: 0,
                        })
                        .collect(),
                    selected_post_girl_id_list: vec![3510028],
                    show_random_selected: false,
                }),
                music_player: Some(MusicPlayerInfo {
                    music_list: context
                        .state
                        .filecfg
                        .music_player_config_template_tb()
                        .data()
                        .unwrap()
                        .iter()
                        .map(|tmpl| MusicPlayerItem {
                            id: tmpl.id() as u32,
                            unlock_time: 1,
                            seen_time: 2,
                        })
                        .collect(),
                }),
                teleport: Some(TeleportUnlockInfo {
                    unlocked_list: context
                        .state
                        .filecfg
                        .teleport_config_template_tb()
                        .data()
                        .unwrap()
                        .iter()
                        .map(|tmpl| tmpl.teleport_id())
                        .collect(),
                }),
                ..Default::default()
            }),
        }
    }

    pub async fn on_get_news_stand_data(
        _context: &mut MessageContext<'_, '_>,
        _request: GetNewsStandDataCsReq,
    ) -> GetNewsStandDataScRsp {
        GetNewsStandDataScRsp {
            retcode: 0,
            news_stand_data: Some(NewsStandData::default()),
        }
    }

    pub async fn on_end_newbie(
        _context: &mut MessageContext<'_, '_>,
        request: EndNewbieCsReq,
    ) -> EndNewbieScRsp {
        debug!("EndNewbie({})", request.group_id);

        EndNewbieScRsp {
            retcode: 0,
            group_id: 0,
        }
    }

    pub async fn on_get_trashbin_hermit_data(
        _context: &mut MessageContext<'_, '_>,
        _request: GetTrashbinHermitDataCsReq,
    ) -> GetTrashbinHermitDataScRsp {
        GetTrashbinHermitDataScRsp {
            retcode: 0,
            trashbin_hermit_data: Some(TrashbinHermitData::default()),
        }
    }

    pub async fn on_get_exploration_data(
        _context: &mut MessageContext<'_, '_>,
        _request: GetExplorationDataCsReq,
    ) -> GetExplorationDataScRsp {
        GetExplorationDataScRsp { retcode: 0 }
    }

    pub async fn on_get_journey_data(
        _context: &mut MessageContext<'_, '_>,
        _request: GetJourneyDataCsReq,
    ) -> GetJourneyDataScRsp {
        GetJourneyDataScRsp {
            retcode: 0,
            journey_data: Some(JourneyData::default()),
        }
    }

    pub async fn on_get_red_dot_list(
        _context: &mut MessageContext<'_, '_>,
        _request: GetRedDotListCsReq,
    ) -> GetRedDotListScRsp {
        GetRedDotListScRsp { retcode: 0 }
    }

    pub async fn on_report_ui_layout_platform(
        _context: &mut MessageContext<'_, '_>,
        _request: ReportUiLayoutPlatformCsReq,
    ) -> ReportUiLayoutPlatformScRsp {
        ReportUiLayoutPlatformScRsp { retcode: 0 }
    }

    pub async fn on_game_log_report(
        _context: &mut MessageContext<'_, '_>,
        request: GameLogReportCsReq,
    ) -> GameLogReportScRsp {
        debug!("{request:?}");
        GameLogReportScRsp { retcode: 0 }
    }

    pub async fn on_trigger_interact(
        _context: &mut MessageContext<'_, '_>,
        _request: TriggerInteractCsReq,
    ) -> TriggerInteractScRsp {
        TriggerInteractScRsp { retcode: 0 }
    }

    pub async fn on_battle_report(
        _context: &mut MessageContext<'_, '_>,
        _request: BattleReportCsReq,
    ) -> BattleReportScRsp {
        BattleReportScRsp { retcode: 0 }
    }

    pub async fn on_play_song(
        _context: &mut MessageContext<'_, '_>,
        _request: PlaySongCsReq,
    ) -> PlaySongScRsp {
        PlaySongScRsp { retcode: 0 }
    }

    pub async fn on_set_music_player_mode(
        _context: &mut MessageContext<'_, '_>,
        _request: SetMusicPlayerModeCsReq,
    ) -> SetMusicPlayerModeScRsp {
        SetMusicPlayerModeScRsp { retcode: 0 }
    }
}
