syntax = "v1"

import "common.api"

info (
	title:   "聚玩搜索服务"
	desc:    "内容搜索与首页推荐"
	author:  "Asadz"
	version: "1.0"
)

type (
	PathIDReq {
		Id int64 `path:"id"`
	}
	SearchReq {
		PageReq
		Q          string  `form:"q,optional"`
		MinPrice   float64 `form:"min,optional"`
		MaxPrice   float64 `form:"max,optional"`
		OnlyOnline bool    `form:"onlyOnline,optional"`
		Sort       string  `form:"sort,optional"`
	}
	SearchResp {
		Items []interface{} `json:"items"` // Mixed items
		Meta  PageMeta      `json:"meta"`
	}
	Favorite {
		Id         string `json:"id"`
		UserId     string `json:"userId"`
		TargetType string `json:"targetType"`
		TargetId   string `json:"targetId"`
		CreatedAt  string `json:"createdAt"`
	}
	FavoriteListResp {
		Items []Favorite `json:"items"`
		Meta  PageMeta   `json:"meta"`
	}
	FavoriteReq {
		TargetType string `json:"targetType"` // player, shop
		TargetId   string `json:"targetId"`
	}
	FavoriteCheckReq {
		PathIDReq
		TargetType string `form:"targetType"`
		TargetId   string `form:"targetId"`
	}
	FavoriteCheckResp {
		Favorited bool `json:"favorited"`
	}
)

@server (
	prefix: api/v1
	group:  search
)
service search-api {
	@doc "统一搜索"
	@handler Search
	get /search (SearchReq) returns (SearchResp)

	@doc "首页推荐"
	@handler Recommendations
	get /recommendations/home (PageReq) returns (SearchResp)
}

@server (
	prefix: api/v1
	group:  favorites
)
service search-api {
	@doc "获取收藏列表"
	@handler ListFavorites
	get /favorites (PageReq) returns (FavoriteListResp)

	@doc "添加收藏"
	@handler AddFavorite
	post /favorites (FavoriteReq) returns (EmptyResp)

	@doc "取消收藏"
	@handler RemoveFavorite
	delete /favorites/:id (PathIDReq) returns (EmptyResp)

	@doc "检查收藏状态"
	@handler CheckFavorite
	get /users/:id/favorites/check (FavoriteCheckReq) returns (FavoriteCheckResp)
}
