import { Type as e } from "typebox";
const t = e.Array(e.Object({
  id: e.String(),
  name: e.String(),
  type: e.String()
}));
e.Object({
  id: e.String(),
  name: e.String(),
  description: e.String(),
  primaryFieldId: e.String(),
  fields: t
});
const i = e.Object({
  externalUrl: e.Optional(e.String()),
  baseId: e.String({
    pattern: "^app[A-Za-z0-9]+$",
    description: 'Airtable Base ID starting with "app"'
  }),
  baseName: e.Optional(e.String({ description: "Airtable Base Name" })),
  tableId: e.String({
    pattern: "^tbl[A-Za-z0-9]+$",
    description: 'Airtable Table ID starting with "tbl"'
  }),
  tableName: e.Optional(e.String({ description: "Table name as shown in Airtable interface" })),
  fields: e.Optional(t)
});
e.Enum([
  "number",
  "checkbox",
  "date",
  "dateTime",
  "email",
  "url",
  "singleLineText",
  "multilineText",
  "singleSelect",
  "multipleSelects"
], { type: "string" });
const r = e.Object({
  spreadsheetId: e.String(),
  spreadsheetUrl: e.Optional(e.String()),
  spreadsheetName: e.Optional(e.String()),
  externalUrl: e.Optional(e.String())
}), a = e.Object({
  url: e.Optional(e.String()),
  id: e.String({
    pattern: "^[A-Za-z0-9\\-]+$",
    description: "Notion Database ID"
  }),
  name: e.String({ description: "Notion Database Name" }),
  properties: e.Any()
});
e.Enum([
  "airtable",
  "google-sheets",
  "notion",
  "internal"
], { type: "string" });
const n = e.Object({ schema: e.Object({}, {
  additionalProperties: !0,
  title: "Schema",
  description: "JSON Schema. Always of type 'object' and representing a row that will be saved.",
  examples: [{
    type: "object",
    properties: {
      firstname: {
        type: "string",
        title: "Firstname"
      },
      lastname: {
        type: "string",
        title: "Lastname"
      },
      email: {
        type: "string",
        format: "email",
        title: "Email"
      }
    },
    required: ["email"],
    title: "Newsletter Subscription"
  }]
}) }), s = e.Object({
  id: e.String({
    title: "ID",
    description: "A unique identifier, e.g., 'newsletter_subscriptions'",
    comment: "A unique identifier, e.g., 'newsletter_subscriptions'"
  }),
  label: e.String({
    title: "Name",
    description: "Human-friendly name",
    comment: "For example, 'Newsletter Subscriptions'"
  }),
  description: e.Optional(e.String({ title: "Description" }))
}), l = e.Object({
  provider: e.Literal("internal", { description: "Always use 'internal' for internal datarecords." }),
  schema: e.Object({}, {
    title: "Schema",
    additionalProperties: !0,
    description: "JSON Schema. Always of type 'object' and representing a row that will be saved in the database.",
    examples: [{
      type: "object",
      properties: {
        firstname: {
          type: "string",
          title: "Firstname"
        },
        lastname: {
          type: "string",
          title: "Lastname"
        },
        email: {
          type: "string",
          format: "email",
          title: "Email"
        }
      },
      required: ["email"],
      title: "Newsletter Subscription"
    }]
  })
}, { examples: [{
  provider: "internal",
  schema: {
    type: "object",
    properties: {
      firstname: {
        type: "string",
        title: "Firstname"
      },
      lastname: {
        type: "string",
        title: "Lastname"
      },
      email: {
        type: "string",
        format: "email",
        title: "Email"
      }
    },
    required: ["email"],
    title: "Newsletter Subscription"
  },
  indexes: [{
    name: "email_index",
    fields: ["email"],
    unique: !0
  }]
}] }), o = e.Evaluate(e.Intersect([
  e.Union([
    e.Object({
      provider: e.Literal("airtable"),
      options: i
    }),
    e.Object({
      provider: e.Literal("google-sheets"),
      options: r
    }),
    e.Object({
      provider: e.Literal("notion"),
      options: a
    }),
    l
  ]),
  s,
  n
])), c = e.Array(o);
export {
  c as d
};
