import apiClient from "@/lib/api/client";
import type { ApiResponse, FaqItem } from "@/lib/api/types";


export const getFaqs = (params?: { page?: number; limit?: number }) =>
  apiClient
    .get<ApiResponse<FaqItem[]>>("/faqs/", { params })
    .then((response) => response.data);

/**
 * `ContactController::store()`.
 *
 * `email` is the only required key. The name and message are stored per
 * language — the form fills whichever pair matches the active locale and
 * leaves the other absent, which is why all four are optional. `max:100`
 * applies to the names only; the messages are unbounded `string`.
 */
export interface CreateContactUsBody {
  email: string;
  /** `max:100`. */
  name_en?: string;
  /** `max:100`. */
  name_ar?: string;
  message_en?: string;
  message_ar?: string;
  /** The active locale, stored so a reply can be written in it. */
  primary_language?: string;
}

/**
 * The created row, through the controller's own `transform()` — not a
 * Resource, so it is declared here. 201.
 *
 * `primary_language` comes back as `$contact->primary_language?->value ??
 * $contact->primary_language`, i.e. the enum's backing string.
 */
export interface ContactUsRecord {
  id: number;
  name_en: string | null;
  name_ar: string | null;
  email: string | null;
  message_en: string | null;
  message_ar: string | null;
  primary_language: string | null;
  /** ISO 8601. */
  created_at: string | null;
}

export const createContactUs = (
  data: CreateContactUsBody
): Promise<ApiResponse<ContactUsRecord>> =>
  apiClient.post("/contact-us/", data).then((r) => r.data);
