package http

import gamev1 "hyapp.local/api/proto/game/v1"

type gameListData struct {
	Games        []gameItemData `json:"games"`
	ServerTimeMS int64          `json:"server_time_ms"`
}

type gameItemData struct {
	GameID       string `json:"game_id"`
	PlatformCode string `json:"platform_code"`
	NameKey      string `json:"name_key"`
	Name         string `json:"name"`
	IconURL      string `json:"icon_url"`
	CoverURL     string `json:"cover_url"`
	Category     string `json:"category"`
	LaunchMode   string `json:"launch_mode"`
	Orientation  string `json:"orientation"`
	MinCoin      int64  `json:"min_coin"`
	Enabled      bool   `json:"enabled"`
	Maintenance  bool   `json:"maintenance"`
	SortOrder    int32  `json:"sort_order"`
}

type gameLaunchData struct {
	SessionID    string `json:"session_id"`
	LaunchURL    string `json:"launch_url"`
	ExpiresAtMS  int64  `json:"expires_at_ms"`
	Orientation  string `json:"orientation"`
	ServerTimeMS int64  `json:"server_time_ms"`
}

func gameListDataFromProto(resp *gamev1.ListGamesResponse) gameListData {
	if resp == nil {
		return gameListData{}
	}
	items := make([]gameItemData, 0, len(resp.GetGames()))
	for _, item := range resp.GetGames() {
		items = append(items, gameItemData{
			GameID:       item.GetGameId(),
			PlatformCode: item.GetPlatformCode(),
			NameKey:      item.GetNameKey(),
			Name:         item.GetName(),
			IconURL:      item.GetIconUrl(),
			CoverURL:     item.GetCoverUrl(),
			Category:     item.GetCategory(),
			LaunchMode:   item.GetLaunchMode(),
			Orientation:  item.GetOrientation(),
			MinCoin:      item.GetMinCoin(),
			Enabled:      item.GetEnabled(),
			Maintenance:  item.GetMaintenance(),
			SortOrder:    item.GetSortOrder(),
		})
	}
	return gameListData{Games: items, ServerTimeMS: resp.GetServerTimeMs()}
}

func gameLaunchDataFromProto(resp *gamev1.LaunchGameResponse) gameLaunchData {
	if resp == nil {
		return gameLaunchData{}
	}
	return gameLaunchData{
		SessionID:    resp.GetSessionId(),
		LaunchURL:    resp.GetLaunchUrl(),
		ExpiresAtMS:  resp.GetExpiresAtMs(),
		Orientation:  resp.GetOrientation(),
		ServerTimeMS: resp.GetServerTimeMs(),
	}
}
