/// <reference types="cypress" />

// Custom commands for DeckForge E2E tests

Cypress.Commands.add("devLogin", (email = "admin@oliver.com") => {
  cy.request("POST", "/api/v1/auth/dev-login", {
    email,
    password: Cypress.env("DEV_AUTH_PASSWORD") || "devpass123",
  }).then((response) => {
    const { token } = response.body;
    window.localStorage.setItem("deckforge_token", token);
  });
});

Cypress.Commands.add("createPresentation", (title = "E2E Test Deck") => {
  const token = window.localStorage.getItem("deckforge_token");
  cy.request({
    method: "POST",
    url: "/api/v1/ppt/presentation/create",
    headers: { Authorization: `Bearer ${token}` },
    body: {
      content: "Test brief content for E2E testing.",
      n_slides: 5,
      language: "English",
      title,
    },
  });
});

declare global {
  namespace Cypress {
    interface Chainable {
      devLogin(email?: string): Chainable<void>;
      createPresentation(title?: string): Chainable<void>;
    }
  }
}

export {};
