/**
 * @packageDocumentation
 * @module api.functional.v1.cash_receipts
 * @nestia Generated by Nestia - https://github.com/samchon/nestia
 */
//================================================================
import type { IConnection } from "@nestia/fetcher";
import { PlainFetcher } from "@nestia/fetcher/lib/PlainFetcher";

import type { ITossCashReceipt } from "../../../structures/ITossCashReceipt";

/**
 * 현금 영수증 발행하기.
 *
 * @param input 입력 정보
 * @returns 현금 영수증 정보
 * @security basic
 * @author Samchon
 *
 * @controller FakeTossCashReceiptsController.create
 * @path POST /v1/cash-receipts
 * @nestia Generated by Nestia - https://github.com/samchon/nestia
 */
export async function create(
  connection: IConnection,
  input: ITossCashReceipt.ICreate,
): Promise<create.Output> {
  return PlainFetcher.fetch(
    {
      ...connection,
      headers: {
        ...connection.headers,
        "Content-Type": "application/json",
      },
    },
    {
      ...create.METADATA,
      template: create.METADATA.path,
      path: create.path(),
    },
    input,
  );
}
export namespace create {
  export type Input = ITossCashReceipt.ICreate;
  export type Output = ITossCashReceipt;

  export const METADATA = {
    method: "POST",
    path: "/v1/cash-receipts",
    request: {
      type: "application/json",
      encrypted: false,
    },
    response: {
      type: "application/json",
      encrypted: false,
    },
    status: 201,
  } as const;

  export const path = () => "/v1/cash-receipts";
}

/**
 * 현금 영수증 취소하기.
 *
 * @param receiptKey 현금 영수증의 {@link ITossCashReceipt.receiptKey }
 * @param input 취소 입력 정보
 * @returns 취소된 현금 영수증 정보
 * @security basic
 * @author Samchon
 *
 * @controller FakeTossCashReceiptsController.cancel
 * @path POST /v1/cash-receipts/:receiptKey/cancel
 * @nestia Generated by Nestia - https://github.com/samchon/nestia
 */
export async function cancel(
  connection: IConnection,
  receiptKey: string,
  input: ITossCashReceipt.ICancel,
): Promise<cancel.Output> {
  return PlainFetcher.fetch(
    {
      ...connection,
      headers: {
        ...connection.headers,
        "Content-Type": "application/json",
      },
    },
    {
      ...cancel.METADATA,
      template: cancel.METADATA.path,
      path: cancel.path(receiptKey),
    },
    input,
  );
}
export namespace cancel {
  export type Input = ITossCashReceipt.ICancel;
  export type Output = ITossCashReceipt;

  export const METADATA = {
    method: "POST",
    path: "/v1/cash-receipts/:receiptKey/cancel",
    request: {
      type: "application/json",
      encrypted: false,
    },
    response: {
      type: "application/json",
      encrypted: false,
    },
    status: 201,
  } as const;

  export const path = (receiptKey: string) =>
    `/v1/cash-receipts/${encodeURIComponent(receiptKey?.toString() ?? "null")}/cancel`;
}
