import { z } from "zod";
import { crmApi } from "@/modules/crm/services/crm-api";
import { createCrmListPage } from "@/modules/crm/components/CrmListCrudPage";
import type { Meeting } from "@/modules/crm/types";

const schema = z.object({
  subject: z.string().min(1),
  starts_at: z.string().min(1),
  ends_at: z.string().optional(),
  location: z.string().optional(),
});

export default createCrmListPage<Meeting>({
  title: "جلسات",
  description: "برنامه‌ریزی و ثبت جلسات فروش.",
  breadcrumb: "جلسات",
  resourceKey: "meetings",
  createSchema: schema,
  editSchema: schema.partial(),
  createDefaults: { subject: "", starts_at: "", ends_at: "", location: "" },
  fields: [
    { name: "subject", label: "موضوع" },
    { name: "starts_at", label: "شروع (ISO datetime)" },
    { name: "ends_at", label: "پایان" },
    { name: "location", label: "مکان" },
  ],
  columns: [
    { key: "subject", header: "موضوع" },
    { key: "starts_at", header: "شروع" },
    { key: "location", header: "مکان" },
    { key: "status", header: "وضعیت" },
  ],
  list: (tid) => crmApi.meetings.list(tid, { page: 1, page_size: 500 }),
  create: (tid, d) => crmApi.meetings.create(tid, d),
  exportColumns: ["subject", "starts_at", "status"],
});
