package common

import "party.at/party/internal/data"

func (app *Application) CastVote(issueID, optionID int64, nonce, signature []byte) error {
	issue, err := app.Models.Issues.Get(issueID)
	if err != nil {
		return err
	}

	vote := &data.Vote{
		OptionID:  optionID,
		Nonce:     nonce,
		Signature: signature,
	}

	return app.Models.Votes.Insert(vote, issue)
}
