"use server"

import { signInByUsername, type SignInOutcome } from "@/lib/services/sign-in"

/**
 * The form's one call to the server.
 *
 * A Server Action rather than a fetch from the browser, because the session
 * cookie has to be set by Next, and the `nextCookies()` plugin in `lib/auth.ts`
 * does exactly that for anything returning a Set-Cookie header from here.
 *
 * The shape of the answer is a reason and never a message. What a person reads
 * is written in the component, in both languages, next to the field it belongs
 * to. A server that returns English prose is a server that has decided which
 * language somebody reads.
 */
export async function attemptSignIn(
  username: string,
  password: string,
): Promise<SignInOutcome> {
  return signInByUsername(username, password)
}
