import { createAction, Property } from '@activepieces/pieces-framework';
import { bokioAuth } from '../common/auth';
import { makeRequest } from '../common/client';
import { HttpMethod } from '@activepieces/pieces-common';

export const getAnInvoice = createAction({
  auth: bokioAuth,
  name: 'getAnInvoice',
  displayName: 'Get an invoice',
  description: 'Retrieve a specific invoice by its ID',
  audience: 'both',
  aiMetadata: { description: 'Retrieves a single invoice from a Bokio company by its invoice ID. Use when you already have the invoice ID and need its full details. Idempotent read-only lookup.', idempotent: true },
  props: {
    invoiceId: Property.ShortText({
      displayName: 'Invoice ID',
      description: 'The ID of the invoice to retrieve',
      required: true,
    }),
  },
  async run(context) {
    const { invoiceId } = context.propsValue;
    const { api_key, companyId } = context.auth.props;

    const response = await makeRequest(
      api_key,
      HttpMethod.GET,
      `/companies/${companyId}/invoices/${invoiceId}`
    );

    return response;
  },
});
