package threads_account

import (
	"context"

	mentioninboxdomain "haixun-backend/internal/model/mention_inbox/domain/usecase"
	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListMentionInboxLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewListMentionInboxLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListMentionInboxLogic {
	return &ListMentionInboxLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ListMentionInboxLogic) ListMentionInbox(req *types.ListMentionInboxHandlerReq) (*types.ListMentionInboxData, error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	result, err := l.svcCtx.MentionInbox.List(l.ctx, mentioninboxdomain.ListRequest{
		TenantID:  tenantID,
		OwnerUID:  uid,
		AccountID: req.ID,
		Page:      req.Page,
		PageSize:  req.PageSize,
	})
	if err != nil {
		return nil, err
	}
	return &types.ListMentionInboxData{
		List: toMentionInboxItems(result.List),
		Pagination: types.PaginationData{
			Total:      result.Pagination.Total,
			Page:       result.Pagination.Page,
			PageSize:   result.Pagination.PageSize,
			TotalPages: result.Pagination.TotalPages,
		},
		ReadyTotal:     result.Pagination.ReadyTotal,
		NewestSyncedAt: result.Pagination.NewestSyncedAt,
	}, nil
}
