<commit_before>// Copyright 2013 The go-toggl AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package toggl

import (
	"errors"
	"fmt"
	"net/url"
	"time"
)

// TimeEntriesService handles communication with the time entries related
// methods of the Toggl API.
//
// Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md
type TimeEntriesService struct {
	client *Client
}

// TimeEntry represents a time entry
type TimeEntry struct {
	ID          int        `json:"id,omitempty"`
	WorkspaceID int        `json:"wid,omitempty"`
	ProjectID   int        `json:"pid,omitempty"`
	TaskID      int        `json:"tid,omitempty"`
	Billable    bool       `json:"billable,omitempty"`
	Start       *time.Time `json:"start,omitempty"`
	Stop        *time.Time `json:"stop,omitempty"`
	Duration    int        `json:"duration,omitempty"`
	CreatedWith string     `json:"created_with,omitempty"`
	Tags        []string   `json:"tags,omitempty"`
	Duronly     bool       `json:"duronly,omitempty"`
	At          int        `json:"at,omitempty"`
}

// TimeEntryResponse acts as a response wrapper where response returns
// in format of "data": TimeEntry's object.
type TimeEntryResponse struct {
	Data *TimeEntry `json:"data,omitempty"`
}

// TimeEntry represents posted data to be sent to time entries endpoint.
type TimeEntryCreate struct {
	TimeEntry *TimeEntry `json:"time_entry,omitempty"`
}

// Create a time entry.
//
// Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md#create-a-time-entry
func (s *TimeEntriesService) Create(te *TimeEntry) (*TimeEntry, error) {
	u := "time_entries"
	tec := &TimeEntryCreate{te}
	req, err := s.client.NewRequest("POST", u, tec)
	if err != nil {
		return nil, err
	}

	data := new(TimeEntryResponse)
	_, err = s.client.Do(req, data)

	return data.Data, err
}

// Start a time entry.
//<commit_msg>Fixed comment on exported type TimeEntryCreate.<commit_after>// Copyright 2013 The go-toggl AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package toggl

import (
	"errors"
	"fmt"
	"net/url"
	"time"
)

// TimeEntriesService handles communication with the time entries related
// methods of the Toggl API.
//
// Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md
type TimeEntriesService struct {
	client *Client
}

// TimeEntry represents a time entry
type TimeEntry struct {
	ID          int        `json:"id,omitempty"`
	WorkspaceID int        `json:"wid,omitempty"`
	ProjectID   int        `json:"pid,omitempty"`
	TaskID      int        `json:"tid,omitempty"`
	Billable    bool       `json:"billable,omitempty"`
	Start       *time.Time `json:"start,omitempty"`
	Stop        *time.Time `json:"stop,omitempty"`
	Duration    int        `json:"duration,omitempty"`
	CreatedWith string     `json:"created_with,omitempty"`
	Tags        []string   `json:"tags,omitempty"`
	Duronly     bool       `json:"duronly,omitempty"`
	At          int        `json:"at,omitempty"`
}

// TimeEntryResponse acts as a response wrapper where response returns
// in format of "data": TimeEntry's object.
type TimeEntryResponse struct {
	Data *TimeEntry `json:"data,omitempty"`
}

// TimeEntryCreate represents posted data to be sent to time entries endpoint.
type TimeEntryCreate struct {
	TimeEntry *TimeEntry `json:"time_entry,omitempty"`
}

// Create a time entry.
//
// Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md#create-a-time-entry
func (s *TimeEntriesService) Create(te *TimeEntry) (*TimeEntry, error) {
	u := "time_entries"
	tec := &TimeEntryCreate{te}
	req, err := s.client.NewRequest("POST", u, tec)
	if err != nil {
		return nil, err
	}

	data := new(TimeEntryResponse)
	_, err = s.client.Do(req, data)

	return data.Data, err
}

// Start a time entry.
//
{'fraction_non_alphanumeric': 0.1203888334995015, 'fraction_numerical': 0.0019940179461615153, 'mean_word_length': 3.4638487208008897, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1033745', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1250, 'n_words': 367}