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 getAJournalEntry = createAction({
  auth: bokioAuth,
  name: 'getAJournalEntry',
  displayName: 'Get a journal entry',
  description: 'Retrieve a specific journal entry by its ID',
  audience: 'both',
  aiMetadata: { description: 'Retrieves a single journal entry from a Bokio company by its UUID. Use when you already have the journal entry ID and need its full bookkeeping details. Idempotent read-only lookup.', idempotent: true },
  props: {
    journalEntryId: Property.ShortText({
      displayName: 'Journal Entry ID',
      description: 'UUID of the journal entry',
      required: true,
    }),
  },
  async run(context) {
    const { journalEntryId } = context.propsValue;
    const { api_key, companyId } = context.auth.props;

    const response = await makeRequest(
      api_key,
      HttpMethod.GET,
      `/companies/${companyId}/journal-entries/${journalEntryId}`
    );

    return response;
  },
});
