import assert from "node:assert/strict";
import {
  AdmissionSchema,
  ContactSchema,
  LoginSchema,
  ProgramSchema,
} from "../app/lib/definitions";

function expectOk(result: { success: boolean }, label: string) {
  assert.equal(result.success, true, `${label} should succeed`);
}

function expectFail(result: { success: boolean }, label: string) {
  assert.equal(result.success, false, `${label} should fail`);
}

expectOk(
  ContactSchema.safeParse({
    name: "Jane Doe",
    email: "jane@example.com",
    phone: "+254700000000",
    subject: "Admissions",
    message: "I would like more information about programs.",
    website: "",
  }),
  "valid contact",
);

expectFail(
  ContactSchema.safeParse({
    name: "J",
    email: "bad",
    phone: "",
    subject: "",
    message: "short",
    website: "",
  }),
  "invalid contact",
);

expectOk(
  AdmissionSchema.safeParse({
    studentFirstName: "Amani",
    studentLastName: "Otieno",
    studentDob: "2015-01-01",
    studentGender: "female",
    currentSchool: "Local School",
    gradeLevel: "Grade 4",
    program: "IGCSE",
    startDate: "2026-09-01",
    parentName: "Parent Name",
    relationship: "Mother",
    email: "parent@example.com",
    phone: "+254711111111",
    notes: "",
    consent: true,
    website: "",
  }),
  "valid admission",
);

expectFail(
  AdmissionSchema.safeParse({
    studentFirstName: "Amani",
    studentLastName: "Otieno",
    studentDob: "2015-01-01",
    gradeLevel: "Grade 4",
    program: "IGCSE",
    startDate: "2026-09-01",
    parentName: "Parent Name",
    relationship: "Mother",
    email: "parent@example.com",
    phone: "+254711111111",
    consent: false,
    website: "",
  }),
  "admission without consent",
);

expectOk(
  LoginSchema.safeParse({
    email: "admin@vidoschool.com",
    password: "secret",
  }),
  "valid login",
);

expectOk(
  ProgramSchema.safeParse({
    title: "Online Tuition",
    description: "Live online lessons with tutor support for flexible learning.",
    sortOrder: 1,
    published: true,
  }),
  "valid program",
);

console.log("validation-smoke: all checks passed");
