<commit_before>package commands

import (
	"fmt"
	"math"
	"strings"
	"time"

	"github.com/pavlo/slack-time/data"
	"github.com/pavlo/slack-time/utils"
)

// Command - public interface
type Command interface {
	Execute(env *utils.Environment) *CommandResult
}

// CommandArguments - this is what a Command needs to operate
type CommandArguments struct {
	slackCommand data.SlackCommand
	rawCommand   string
}

// CommandResult - is what command's Execute method returns
type CommandResult struct {
	data map[string]interface{}
}

// Get - looks up a Command that would serve the corresponding Slack Command
func Get(slackCommand data.SlackCommand) (Command, error) {
	userInput := slackCommand.Text
	if strings.HasPrefix(userInput, "start") {
		cmd := Start{CommandArguments: createCommandArguments(slackCommand, "start")}
		return cmd, nil
	} else if strings.HasPrefix(userInput, "stop") {
		cmd := Stop{CommandArguments: createCommandArguments(slackCommand, "stop")}
		return cmd, nil
	} else if strings.HasPrefix(userInput, "status") {
		cmd := Status{CommandArguments: createCommandArguments(slackCommand, "status")}
		return cmd, nil
	}
	return nil, fmt.Errorf("Failed to look up a command for `%s` name", userInput)
}

// MarkTimerAsFinished performs housekeeping when a timer is finishing:
// 1. Calculates how many minutes the task was started
// 2. Adds the minutes to task's TotalMinutes
// Note, it does not update objects in DB!
func MarkTimerAsFinished(task *data.Task, t *data.Timer) {
	now := time.Now()
	duration := time.Since(t.StartedAt)
	t.FinishedAt = &now
	t.Minutes = int(math.Floor(duration.Minutes()))
	task.TotalMinutes = task.TotalMinutes + t.Minutes
}

// CreateMainEntitiesIfNeeded lazily creates Team, TeamUser and Project
func CreateMainEntitiesIfNeeded(env *utils.Environment, slackCommand data.SlackCommand) (*data.Team, *data.TeamUser, *data.Project) {
	dao := &data.Dao{DB: env.OrmDB}<commit_msg>disables Status command for now<commit_after>package commands

import (
	"fmt"
	"math"
	"strings"
	"time"

	"github.com/pavlo/slack-time/data"
	"github.com/pavlo/slack-time/utils"
)

// Command - public interface
type Command interface {
	Execute(env *utils.Environment) *CommandResult
}

// CommandArguments - this is what a Command needs to operate
type CommandArguments struct {
	slackCommand data.SlackCommand
	rawCommand   string
}

// CommandResult - is what command's Execute method returns
type CommandResult struct {
	data map[string]interface{}
}

// Get - looks up a Command that would serve the corresponding Slack Command
func Get(slackCommand data.SlackCommand) (Command, error) {
	userInput := slackCommand.Text
	if strings.HasPrefix(userInput, "start") {
		cmd := Start{CommandArguments: createCommandArguments(slackCommand, "start")}
		return cmd, nil
	} else if strings.HasPrefix(userInput, "stop") {
		cmd := Stop{CommandArguments: createCommandArguments(slackCommand, "stop")}
		return cmd, nil
	}
	// else if strings.HasPrefix(userInput, "status") {
	// 	cmd := Status{CommandArguments: createCommandArguments(slackCommand, "status")}
	// 	return cmd, nil
	// }
	return nil, fmt.Errorf("Failed to look up a command for `%s` name", userInput)
}

// MarkTimerAsFinished performs housekeeping when a timer is finishing:
// 1. Calculates how many minutes the task was started
// 2. Adds the minutes to task's TotalMinutes
// Note, it does not update objects in DB!
func MarkTimerAsFinished(task *data.Task, t *data.Timer) {
	now := time.Now()
	duration := time.Since(t.StartedAt)
	t.FinishedAt = &now
	t.Minutes = int(math.Floor(duration.Minutes()))
	task.TotalMinutes = task.TotalMinutes + t.Minutes
}

// CreateMainEntitiesIfNeeded lazily creates Team, TeamUser and Project
func CreateMainEntitiesIfNeeded(env *utils.Environment, slackCommand data.SlackCommand) (*data.Team, *data.TeamUser, *data.Project) {
	dao := &data.Dao{DB: env.OrmDB}
{'fraction_non_alphanumeric': 0.11216876768716233, 'fraction_numerical': 0.0010290712631849757, 'mean_word_length': 4.873111782477341, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4696368', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1218, 'n_words': 353}