// PaginatedFindAll can be used to load users in chunks
195667
func (s UserResource) PaginatedFindAll(r api2go.Request) (uint, api2go.Responder, error) {
	var (
		result                      []model.User
		number, size, offset, limit string
		keys                        []int
	)
	users := s.UserStorage.GetAll()

	for k := range users {
		i, err := strconv.ParseInt(k, 10, 64)
		if err != nil {
			return 0, &Response{}, err
		}

		keys = append(keys, int(i))
	}
	sort.Ints(keys)

	numberQuery, ok := r.QueryParams["page[number]"]
	if ok {
		number = numberQuery[0]
	}
	sizeQuery, ok := r.QueryParams["page[size]"]
	if ok {
		size = sizeQuery[0]
	}
	offsetQuery, ok := r.QueryParams["page[offset]"]
	if ok {
		offset = offsetQuery[0]
	}
	limitQuery, ok := r.QueryParams["page[limit]"]
	if ok {
		limit = limitQuery[0]
	}

	if size != "" {
		sizeI, err := strconv.ParseUint(size, 10, 64)
		if err != nil {
			return 0, &Response{}, err
		}

		numberI, err := strconv.ParseUint(number, 10, 64)
		if err != nil {
			return 0, &Response{}, err
		}

		start := sizeI * (numberI - 1)
		for i := start; i < start+sizeI; i++ {
			if i >= uint64(len(users)) {
				break
			}
			result = append(result, *users[strconv.FormatInt(int64(keys[i]), 10)])
		}
	} else {
		limitI, err := strconv.ParseUint(limit, 10, 64)
		if err != nil {
			return 0, &Response{}, err
		}

		offsetI, err := strconv.ParseUint(offset, 10, 64)
		if err != nil {
			return 0, &Response{}, err
		}

		for i := offsetI; i < offsetI+limitI; i++ {
			if i >= uint64(len(users)) {
				break
			}
			result = append(result, *users[strconv.FormatInt(int64(keys[i]), 10)])
		}
	}

	return uint(len(users)), &Response{Res: result}, nil
}
1297446
func NewPaginationMeta(offset, limit int, hasMore bool, currentURL string) PaginationMeta {
	pm := PaginationMeta{
		Limit:         limit,
		CurrentOffset: offset,
	}

	// Calculate next/prev offsets, leave nil if not valid pages
	nextOffset := offset + limit
	if hasMore {
		pm.NextOffset = &nextOffset
	}

	prevOffset := offset - limit
	if prevOffset < 0 {
		prevOffset = 0
	}
	if prevOffset < offset {
		pm.PrevOffset = &prevOffset
	}

	// If URL format provided, populate URLs. Intentionally swallow URL errors for now, API should
	// catch missing URLs if we call with bad URL arg (and we care about them being present).
	if currentURL != "" && pm.NextOffset != nil {
		pm.NextURL, _ = setQueryParam(currentURL, "offset", *pm.NextOffset, 0)
	}
	if currentURL != "" && pm.PrevOffset != nil {
		pm.PrevURL, _ = setQueryParam(currentURL, "offset", *pm.PrevOffset, 0)
	}

	return pm
}
207009
func (c *Client) GetUsersPublicProfile(userID ID) (*User, error) {
	spotifyURL := c.baseURL + "users/" + string(userID)

	var user User

	err := c.get(spotifyURL, &user)
	if err != nil {
		return nil, err
	}

	return &user, nil
}
413878
func ServerFinalizer(f ...ServerFinalizerFunc) ServerOption {
	return func(s *Server) { s.finalizer = append(s.finalizer, f...) }
}
1201337
func (client *Client) PaginateRunstatusServices(ctx context.Context, page RunstatusPage, callback func(*RunstatusService, error) bool) { // nolint: dupl
	if page.ServicesURL == "" {
		callback(nil, fmt.Errorf("empty Services URL for %#v", page))
		return
	}

	servicesURL := page.ServicesURL
	for servicesURL != "" {
		resp, err := client.runstatusRequest(ctx, servicesURL, nil, "GET")
		if err != nil {
			callback(nil, err)
			return
		}

		var ss *RunstatusServiceList
		if err := json.Unmarshal(resp, &ss); err != nil {
			callback(nil, err)
			return
		}

		for i := range ss.Services {
			if err := ss.Services[i].FakeID(); err != nil {
				log.Printf("bad fake ID for %#v, %s", ss.Services[i], err)
			}

			if cont := callback(&ss.Services[i], nil); !cont {
				return
			}
		}

		servicesURL = ss.Next
	}
}
1276716
func (c *ReportingClient) RunFinished(ctx context.Context, args RunFinishedArgs) error {
	return c.postJSON("runfinished", args)
}
21487
func NewListUsersOnFolderArgs(DocId string) *ListUsersOnFolderArgs {
	s := new(ListUsersOnFolderArgs)
	s.DocId = DocId
	s.Limit = 1000
	return s
}
830436
func GetHugepageLimitData(pid int, cgPath string) ([]rspec.LinuxHugepageLimit, error) {
	return nil, fmt.Errorf("unimplemented yet")
}
1187160
func (c *Config) LoadIteratorToDepth(ctx context.Context, qs graph.QuadStore, dst reflect.Value, depth int, list graph.Iterator) error {
	if depth >= 0 {
		// 0 depth means "current level only" for user, but it's easier to make depth=0 a stop condition
		depth++
	}
	l := c.newLoader(qs)
	return l.loadIteratorToDepth(ctx, dst, depth, list)
}
675615
func ServerFinalizer(f httptransport.ServerFinalizerFunc) ServerOption {
	return func(s *Server) { s.finalizer = f }
}
730371
func (account *Account) PendingFollowRequests() ([]User, error) {
	insta := account.inst
	resp, err := insta.sendRequest(
		&reqOptions{
			Endpoint: urlFriendshipPending,
		},
	)
	if err != nil {
		return nil, err
	}

	var result struct {
		Users []User `json:"users"`
		// TODO: pagination
		// TODO: SuggestedUsers
		Status string `json:"status"`
	}
	err = json.Unmarshal(resp, &result)
	if err != nil {
		return nil, err
	}
	if result.Status != "ok" {
		return nil, fmt.Errorf("bad status: %s", result.Status)
	}

	return result.Users, nil
}
931779
func paginationQuery(options *ListOptions) string {
	query := url.Values{}
	query.Set("limit", strconv.Itoa(options.Limit))
	query.Set("offset", strconv.Itoa(options.Offset))

	return query.Encode()
}
177884
func (client *Client) Paginate(g Listable, callback IterateItemFunc) {
	ctx, cancel := context.WithTimeout(context.Background(), client.Timeout)
	defer cancel()

	client.PaginateWithContext(ctx, g, callback)
}
907512
func NewUploadSessionFinishBatchArg(Entries []*UploadSessionFinishArg) *UploadSessionFinishBatchArg {
	s := new(UploadSessionFinishBatchArg)
	s.Entries = Entries
	return s
}
100437
func LoadIteratorToDepth(ctx context.Context, qs graph.QuadStore, dst reflect.Value, depth int, list graph.Iterator) error {
	return global.LoadIteratorToDepth(ctx, qs, dst, depth, list)
}
743882
func forEachUser(ctx context.Context, tx *bolt.Tx, fn func(*platform.User) bool) error {
	cur := tx.Bucket(userUser).Cursor()
	for k, v := cur.First(); k != nil; k, v = cur.Next() {
		u := &platform.User{}
		if err := json.Unmarshal(v, u); err != nil {
			return err
		}
		if !fn(u) {
			break
		}
	}

	return nil
}
105645
func Pagination(pagination interface{}, opts Options) (*Tag, error) {
	if p, ok := pagination.(Paginator); ok {
		return p.Tag(opts)
	}

	p := Paginator{
		Page:    1,
		PerPage: 20,
	}

	return p.TagFromPagination(pagination, opts)
}