import type { APIService } from './API';

export interface FetchedAPRSPacket {
  id?: number;
  radio_id?: number;
  radio?: {
    id?: number;
    name?: string;
  };
  src?: string;
  source?: string;
  dst?: string;
  destination?: string;
  path?: string;
  comment?: string;
  latitude?: number | { Float64?: number; Valid?: boolean } | null;
  longitude?: number | { Float64?: number; Valid?: boolean } | null;
  symbol?: string;
  raw?: string;
  payload?: string;
  received_at?: string;
  timestamp?: string;
  time?: string;
  created_at?: string;
}

export class APRSServiceImpl {
  private api: APIService;

  constructor(api: APIService) {
    this.api = api;
  }

  public async fetchPackets(limit = 200): Promise<FetchedAPRSPacket[]> {
    const endpoint = '/aprs/packets';
    const params = { limit };
    return this.api.fetch<FetchedAPRSPacket[]>(endpoint, { params });
  }
}

export default APRSServiceImpl;
