/**
 * Platform-abstracted screen object pattern (Phase 4).
 * Business actions depend on Screen API; Android/iOS supply locators only.
 */
export type Platform = "android" | "ios";

export type LoginLocators = {
  username: string;
  password: string;
  submit: string;
};

export const androidLoginLocators: LoginLocators = {
  username: "~username",
  password: "~password",
  submit: "~login-button",
};

export const iosLoginLocators: LoginLocators = {
  username: "~username",
  password: "~password",
  submit: "~login-button",
};

export function loginLocatorsFor(platform: Platform): LoginLocators {
  return platform === "ios" ? iosLoginLocators : androidLoginLocators;
}

/** Screen API — shared across platforms; steps never branch on platform. */
export class LoginScreen {
  constructor(
    private readonly driver: { $(sel: string): { setValue(v: string): Promise<void>; click(): Promise<void> } },
    private readonly locators: LoginLocators,
  ) {}

  async login(user: string, pass: string): Promise<void> {
    await this.driver.$(this.locators.username).setValue(user);
    await this.driver.$(this.locators.password).setValue(pass);
    await this.driver.$(this.locators.submit).click();
  }
}
