import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
import { expect } from "e2e";
import * as Effect from "effect/Effect";
import { T3_HOME } from "../e2e.config.ts";
import { rpcClient, runPromise, test, WEB } from "./t3.ts";

test("CamelCase Claude accounts have distinct badges", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("Badge demonstration");
  const thread = await t3.thread({ project, title: "Account badges", messages: ["Reply with just the word ok."] });
  await runPromise(Effect.gen(function* () {
    const client = yield* rpcClient(T3_HOME, app.baseUrl ?? "");
    for (const [id, displayName] of [["claudeAgent", "ClaudeProx"], ["claudeAgent_claudeapi", "ClaudeAPI"]]) {
      yield* client["server.updateSettings"]({ patch: {}, providerInstanceMutation: {
        operation: "upsert", instanceId: ProviderInstanceId.make(id!),
        instance: { driver: ProviderDriverKind.make("claudeAgent"), enabled: true, displayName },
      }});
    }
  }).pipe(Effect.scoped));
  await t3.open(thread);
  await browser.locator("[data-chat-provider-model-picker]").tap();
  await browser.locator('[data-model-picker-provider="claudeAgent"] button').waitFor();
  await app.screenshot("claude-provider-rail");
  await screen.getByPlaceholder("Search models...").fill("Haiku");
  await screen.getByRole("option", "Claude Haiku 5.5 , ClaudeProx Add to favorites", { exact: true }).waitFor();
  await app.screenshot("claude-haiku-account-badges");
  await expect(screen.getByRole("option", "Claude Haiku 5.5 , ClaudeProx Add to favorites", { exact: true })).toContainText("CP");
  await expect(screen.getByRole("option", "Claude Haiku 5.5 , ClaudeAPI Add to favorites", { exact: true })).toContainText("CA");
});
