1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: AGPL-3.0-or-later
4
5package lunatask
6
7import (
8 "context"
9 "fmt"
10 "net/http"
11)
12
13// TrackHabitActivityRequest represents the request to track a habit activity.
14type TrackHabitActivityRequest struct {
15 // PerformedOn is the date when the activity was performed.
16 PerformedOn Date `json:"performed_on"`
17}
18
19// TrackHabitActivityResponse represents the response from Lunatask API when tracking a habit activity.
20type TrackHabitActivityResponse struct {
21 Status string `json:"status"`
22 Message string `json:"message,omitempty"`
23}
24
25// TrackHabitActivity tracks an activity for a habit in Lunatask.
26// The PerformedOn field must be an ISO-8601 date (e.g., "2024-08-26").
27func (c *Client) TrackHabitActivity(ctx context.Context, habitID string, request *TrackHabitActivityRequest) (*TrackHabitActivityResponse, error) {
28 if habitID == "" {
29 return nil, fmt.Errorf("%w: habit ID cannot be empty", ErrBadRequest)
30 }
31 if request.PerformedOn.IsZero() {
32 return nil, fmt.Errorf("%w: performed_on is required", ErrBadRequest)
33 }
34
35 resp, _, err := doJSON[TrackHabitActivityResponse](c, ctx, http.MethodPost, "/habits/"+habitID+"/track", request)
36 if err != nil {
37 return nil, err
38 }
39
40 return resp, nil
41}