package action

import (
	"context"
	"jiraport/service/jira"
	ntf "jiraport/service/notification"
)

type CommentCommand struct {
	jira *jira.Jira
}

func NewCommentCommand(jira *jira.Jira) (*CommentCommand, error) {
	return &CommentCommand{jira: jira}, nil
}

func (cmd *CommentCommand) Exec(ctx context.Context, actionExecInfo *ntf.NotificationActionExecInfo, args ...string) (bool, error) {
	if len(args) == 0 {
		return true, nil
	}
	comment := args[0]
	err := cmd.jira.AddComment(actionExecInfo.Notification.IssueKey, comment)
	if err != nil {
		return false, err
	}
	return true, nil
}
