import type { AdapterResult, AssessmentSchema } from "../types";
import { commercialGet, failResult } from "./http";

export async function loadAssessmentSchema(): Promise<AdapterResult<AssessmentSchema>> {
  const res = await commercialGet<AssessmentSchema>("/api/v1/commercial/assessment/schema");
  if (!res.ok) {
    return failResult(res.availability, res.message || "اسکیمای ارزیابی در دسترس نیست", {
      schema_version: "0",
      questions: [],
    });
  }
  const questions = res.data.questions ?? [];
  return {
    availability: questions.length ? "ready" : "empty",
    data: res.data,
    source: "commercial.assessment",
    message: questions.length ? undefined : "اسکیما خالی است",
  };
}
