import {z} from 'zod' export type AviationRptAirportsDTO = {icao: string, name: string, country: string, countryType: 'EEA_COUNTRY' | 'EEA_DEPENDENT_COUNTRY' | 'EFTA_COUNTRY' | 'ACCESSION' | 'CLOSELY_CONNECTED_TO_EEA_COUNTRY' | 'THIRD_COUNTRY' | 'UKETS_FLIGHTS_TO_EEA_REPORTED' | 'UKETS_FLIGHTS_TO_EEA_NOT_REPORTED', state: string}; export type AviationAerUkEtsAggregatedEmissionDataDetails = {airportFrom: AviationRptAirportsDTO, airportTo: AviationRptAirportsDTO, fuelConsumption: unknown, flightsNumber: number, fuelType: 'JET_KEROSENE' | 'JET_GASOLINE' | 'AVIATION_GASOLINE'}; export type AviationAerUkEtsAggregatedEmissionsData = {aggregatedEmissionDataDetails: Array}; export type AviationAerSafPurchase = {fuelName: string, batchNumber: string, safMass: unknown, sustainabilityCriteriaEvidenceType: 'SCREENSHOT_FROM_RTFO_REGISTRY' | 'VOLUNTARY_CERTIFICATION_SCHEME_MARKING' | 'FUEL_SUPPLIER_REPORT' | 'OTHER', otherSustainabilityCriteriaEvidenceDescription?: string | undefined, evidenceFiles?: Array | undefined}; export type AviationAerSafDetails = {purchases: Array, noDoubleCountingDeclarationFile: string, totalSafMass: unknown, emissionsFactor: unknown, totalEmissionsReductionClaim: unknown}; export type AviationAerSaf = {exist: boolean, safDetails?: AviationAerSafDetails | undefined}; export type AviationAerEmissionsCalculationDTO = {aggregatedEmissionsData: AviationAerUkEtsAggregatedEmissionsData, saf: AviationAerSaf}; export type CreateApiV10AviationReportingUketsStandardFuelsEmissionsArgs = {body: AviationAerEmissionsCalculationDTO}; export type CreateApiV10AviationReportingUketsStandardFuelsEmissionsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const standardFuelsTotalEmissions = z.object({fuelType: z.enum(["JET_KEROSENE", "JET_GASOLINE", "AVIATION_GASOLINE"]), emissionsFactor: z.string(), netCalorificValue: z.string(), fuelConsumption: z.string(), emissions: z.string()}); export const createApiV10AviationReportingUketsStandardFuelsEmissionsResponse = z.array(standardFuelsTotalEmissions); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Retrieves total emissions for standard fuels * * POST /v1.0/aviation-reporting/ukets/standard-fuels-emissions */ export const createApiV10AviationReportingUketsStandardFuelsEmissions = async (args: CreateApiV10AviationReportingUketsStandardFuelsEmissionsArgs, options?: CreateApiV10AviationReportingUketsStandardFuelsEmissionsOptions) => { const {baseUrl = "http://localhost:8080/api", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1.0/aviation-reporting/ukets/standard-fuels-emissions${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV10AviationReportingUketsStandardFuelsEmissionsResponse, await res.json()) };