import { baseAPI } from "@/Shared/API/baseAPI";
import axios, { AxiosError } from "axios";

interface IAuthor {
  id: number;
  first_name: string;
  last_name: string;
  govern_status: any;
}

interface ILocation {
  id: number;
  latitude: string;
  longitude: string;
  address: string;
}

interface IImage {
  id: number;
  image: string;
}

interface IReport {
  id: number;
  created_at: string;
  location: ILocation[];
  category: number;
  description: string;
  total_likes: number;
  author: IAuthor;
  image: IImage[];
}

class ReportDetailsStore {
  error: string;
  constructor() {
    this.error = "";
  }

  async getReportDetails(id: string) {
    try {
      const response = await axios.get<IReport>(
        `${baseAPI}/report/${id}/`
      );

      return response.data;
    } catch (error: unknown) {
      if (error instanceof AxiosError) {
        this.error = error.message;
      } else {
        this.error = "An error occured";
      }
    }
  }
}

export const reportDetailsStore = new ReportDetailsStore();
