package app

import (
	"code.tnxs.net/taxnexus/lib/api/regs/regs_client/transaction"
	"code.tnxs.net/taxnexus/lib/api/regs/regs_models"
)

// PostTransactions is a first class object type storage method
func PostTransactions(objList []*TaxTransaction, principal *User) error {
	swagList := []*regs_models.Transaction{}
	for _, itm := range objList {
		swagList = append(swagList, &regs_models.Transaction{
			AccountID:        itm.AccountID,
			TaxTransactionID: itm.ID,
			TaxTypeID:        itm.TaxTypeID,
			Valid:            true,
		})
	}
	regsParams := transaction.NewPostTransactionsParamsWithTimeout(postTimeout)
	regsParams.TransactionRequest = &regs_models.TransactionRequest{
		Data: swagList,
	}
	_, err := regsClient.Transaction.PostTransactions(regsParams, principal.Auth)
	if err != nil {
		return err
	}
	return nil
}
