"use client";

import { apiClient, getDataOrThrow } from "@/core/api";
import {
  residenceCardVerificationSchema,
  type ResidenceCardVerification,
} from "@customer-portal/domain/customer";

export const verificationService = {
  async getResidenceCardVerification(): Promise<ResidenceCardVerification> {
    const response = await apiClient.GET<ResidenceCardVerification>(
      "/api/verification/residence-card"
    );
    const data = getDataOrThrow(response, "Failed to load residence card verification status");
    return residenceCardVerificationSchema.parse(data);
  },

  async submitResidenceCard(file: File): Promise<ResidenceCardVerification> {
    const form = new FormData();
    form.set("file", file);

    const response = await apiClient.POST<ResidenceCardVerification>(
      "/api/verification/residence-card",
      {
        body: form,
      }
    );
    const data = getDataOrThrow(response, "Failed to submit residence card");
    return residenceCardVerificationSchema.parse(data);
  },
};
