/*
  This file is part of TALER
  Copyright (C) 2026 Taler Systems SA

  TALER is free software; you can redistribute it and/or modify it under the
  terms of the GNU General Public License as published by the Free Software
  Foundation; either version 3, or (at your option) any later version.

  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along with
  TALER; see the file COPYING.  If not, see
  <http://www.gnu.org/licenses/>
*/
/**
 * @file bank-lib/bank_api_helper.c
 * @brief convenience functions for the ``struct TALER_BANK_TransferSubject``
 * @author Christian Grothoff
 */
#include "bank_api_common.h"
#include <microhttpd.h> /* just for HTTP status codes */
#include "taler/taler_signatures.h"


void
TALER_BANK_transfer_subject_copy (
  struct TALER_BANK_TransferSubject *dst,
  const struct TALER_BANK_TransferSubject *src)
{
  dst->format = src->format;

  switch (src->format)
  {
  case TALER_BANK_SUBJECT_FORMAT_SIMPLE:
    dst->details.simple.credit_amount = src->details.simple.credit_amount;
    dst->details.simple.subject =
      (src->details.simple.subject != NULL)
      ? GNUNET_strdup (src->details.simple.subject)
      : NULL;
    return;

  case TALER_BANK_SUBJECT_FORMAT_URI:
    dst->details.uri.uri =
      (src->details.uri.uri != NULL)
      ? GNUNET_strdup (src->details.uri.uri)
      : NULL;
    return;

  case TALER_BANK_SUBJECT_FORMAT_CH_QR_BILL:
    dst->details.ch_qr_bill.credit_amount =
      src->details.ch_qr_bill.credit_amount;
    dst->details.ch_qr_bill.qr_reference_number =
      (src->details.ch_qr_bill.qr_reference_number != NULL)
      ? GNUNET_strdup (src->details.ch_qr_bill.qr_reference_number)
      : NULL;
    return;
  }
  GNUNET_break (0);
}


void
TALER_BANK_transfer_subject_free (
  struct TALER_BANK_TransferSubject *subject)
{
  switch (subject->format)
  {
  case TALER_BANK_SUBJECT_FORMAT_SIMPLE:
    GNUNET_free (subject->details.simple.subject);
    return;

  case TALER_BANK_SUBJECT_FORMAT_URI:
    GNUNET_free (subject->details.uri.uri);
    return;

  case TALER_BANK_SUBJECT_FORMAT_CH_QR_BILL:
    GNUNET_free (subject->details.ch_qr_bill.qr_reference_number);
    return;
  }
  GNUNET_break (0);
}
