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 { ElectricityRateReadResponse } from '../../../models/responses';

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

// Endpoint: GET /public-api/resources/electricity-rates/v2.0/{electricityRate}

export const electricityRateReadAction = createAction({
  auth: ampecoAuth,
  name: 'electricityRateRead',
  displayName: 'Resources - Electricity Rates - Read',
  description: 'Get a single Electricity rate.',
  audience: 'both',
  aiMetadata: { description: 'Retrieve one electricity rate from AMPECO by its numeric id, including its name, default price, tax and utility. Read-only and safe to repeat. Use when you have a specific rate id; to discover ids, list rates instead.', idempotent: true },
  props: {
        
  electricityRate: Property.Number({
    displayName: 'Electricity Rate',
    description: '',
    required: true,
  }),
  },
  async run(context): Promise<ElectricityRateReadResponse> {
    try {
      const url = processPathParameters('/public-api/resources/electricity-rates/v2.0/{electricityRate}', context.propsValue);
      
      const queryParams = prepareQueryParams(context.propsValue, []);
      
      const body = undefined;

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

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