import { HttpMethod } from '@activepieces/pieces-common';
import { createAction, Property } from '@activepieces/pieces-framework';
import { ampecoAuth } from '../../../common/auth';
import { handleApiError, makeAmpecoApiCall, prepareQueryParams, processPathParameters } from '../../../common/utils';
import { GetConfigurationTemplateResponse } from '../../../models/responses';

/**
 * Generated from API version: 3.96.4
 */

// Endpoint: GET /public-api/resources/configuration-templates/v1.0/{template}

export const getConfigurationTemplateAction = createAction({
  auth: ampecoAuth,
  name: 'getConfigurationTemplate',
  displayName: 'Resources - Configuration Templates - Get Configuration Template',
  description: 'Get Configuration Template.',
  audience: 'both',
  aiMetadata: { description: 'Retrieve a single OCPP configuration template by its numeric id. Read-only and idempotent; use this when you already know the template id, and use List Configuration Templates to search across templates.', idempotent: true },
  props: {
        
  template: Property.Number({
    displayName: 'Template',
    description: '',
    required: true,
  }),
  },
  async run(context): Promise<GetConfigurationTemplateResponse> {
    try {
      const url = processPathParameters('/public-api/resources/configuration-templates/v1.0/{template}', context.propsValue);
      
      const queryParams = prepareQueryParams(context.propsValue, []);
      
      const body = undefined;

      
      return await makeAmpecoApiCall(
        context.auth,
        url,
        HttpMethod.GET,
        body,
        queryParams
      ) as GetConfigurationTemplateResponse;

    } catch (error) {
      handleApiError(error);
    }
  },
});
