import { requireStringField } from "./tool-helpers.mjs";

export function createSyncMailboxTool(client) {
  return {
    name: "productier_sync_mailbox",
    description: "Trigger mailbox sync and return the updated mailbox state.",
    inputSchema: {
      type: "object",
      properties: {
        mailboxId: { type: "string", description: "Mailbox id to sync." }
      },
      required: ["mailboxId"],
      additionalProperties: false
    },
    async invoke(rawInput = {}) {
      const mailboxId = requireStringField(rawInput.mailboxId, "mailboxId");
      const response = await client.syncMailbox(mailboxId);
      return {
        synced: true,
        mailboxId,
        mailbox: response?.data ?? null
      };
    }
  };
}
