import type { CollectionConfig } from "payload";

export const FormSubmissions: CollectionConfig = {
  slug: "form-submissions",
  admin: {
    useAsTitle: "name",
    defaultColumns: ["name", "email", "company", "createdAt"],
    description: "Captured leads from Contact Form.",
  },
  access: {
    read: ({ req: { user } }) =>
      Boolean(user) || process.env.NODE_ENV === "development",
    update: ({ req: { user } }) =>
      Boolean(user) || process.env.NODE_ENV === "development",
    delete: ({ req: { user } }) =>
      Boolean(user) || process.env.NODE_ENV === "development",
    create: () => false, // Only system creates submissions
  },
  fields: [
    {
      name: "name",
      type: "text",
      required: true,
      admin: { readOnly: true },
    },
    {
      name: "email",
      type: "email",
      required: true,
      admin: { readOnly: true },
    },
    {
      name: "company",
      type: "text",
      admin: { readOnly: true },
    },
    {
      name: "message",
      type: "textarea",
      required: true,
      admin: { readOnly: true },
    },
  ],
};
