package quote_response_mapper_v2

import (
	"github.com/tech/sendico/pkg/merrors"
	quotationv2 "github.com/tech/sendico/pkg/proto/payments/quotation/v2"
)

type executionDecision struct {
	state       quotationv2.QuoteState
	blockReason quotationv2.QuoteBlockReason
}

func validateStatusInvariants(status QuoteStatus) (executionDecision, error) {
	if status.State == quotationv2.QuoteState_QUOTE_STATE_UNSPECIFIED {
		return executionDecision{}, merrors.InvalidArgument("status.state is required")
	}
	if status.State == quotationv2.QuoteState_QUOTE_STATE_BLOCKED {
		if status.BlockReason == quotationv2.QuoteBlockReason_QUOTE_BLOCK_REASON_UNSPECIFIED {
			return executionDecision{}, merrors.InvalidArgument("status.block_reason is required for blocked quote")
		}
		return executionDecision{
			state:       status.State,
			blockReason: status.BlockReason,
		}, nil
	}
	if status.BlockReason != quotationv2.QuoteBlockReason_QUOTE_BLOCK_REASON_UNSPECIFIED {
		return executionDecision{}, merrors.InvalidArgument("status.block_reason is only valid for blocked quote")
	}
	return executionDecision{
		state:       status.State,
		blockReason: quotationv2.QuoteBlockReason_QUOTE_BLOCK_REASON_UNSPECIFIED,
	}, nil
}
