package recommend

import (
	"context"
	"server/internal/model"
	"server/internal/service"

	v1 "server/api/recommend/v1"
)

func (c *ControllerV1) AppList(ctx context.Context, req *v1.AppListReq) (res *v1.AppListRes, err error) {
	out, err := service.BookRecommendations().AppList(ctx, &model.BookRecommendationsListIn{
		Page:   req.Page,
		Size:   req.Size,
		Type:   req.Type,
		Status: req.Status,
	})
	if err != nil {
		return nil, err
	}
	// 转换为 RecommendAppItem
	list := make([]model.RecommendAppItem, 0, len(out.List))
	for _, item := range out.List {
		list = append(list, model.RecommendAppItem{
			Id:        item.Id,
			BookId:    item.BookId,
			CoverUrl:  item.CoverUrl,
			SortOrder: item.SortOrder,
		})
	}
	return &v1.AppListRes{
		Total: out.Total,
		List:  list,
	}, nil
}
