import { apiFetch } from "../lib/api";

export type FeedbackType =
  | "TRUCK_DID_NOT_PASS"
  | "RATING"
  | "SUGGESTION"
  | "OTHER";

export interface FeedbackPayload {
  type: FeedbackType;
  message: string;
  rating?: number;
}

export interface FeedbackItem {
  id: string;
  userId: number;
  type: FeedbackType;
  message: string;
  rating?: number;
  createdAt: string;
}

export const submitFeedback = (payload: FeedbackPayload) =>
  apiFetch<FeedbackItem>("/api/feedback", {
    method: "POST",
    body: JSON.stringify(payload),
  });

export const listMyFeedback = () =>
  apiFetch<FeedbackItem[]>("/api/feedback/me");
