import 'dart:async';

import 'package:pshared/models/account/account.dart';
import 'package:pshared/models/auth/login_outcome.dart';
import 'package:pshared/provider/account.dart';

import 'package:pweb/services/posthog.dart';


class PwebAccountProvider extends AccountProvider {
  @override
  Future<LoginOutcome> login({
    required String email,
    required String password,
    required String locale,
  }) async {
    final outcome = await super.login(
      email: email,
      password: password,
      locale: locale,
    );
    unawaited(PosthogService.login(pending: outcome.isPending));
    return outcome;
  }

  @override
  Future<void> onAccountChanged(Account? previous, Account? current) {
    if (current != null) {
      return PosthogService.identify(current);
    }
    return PosthogService.reset();
  }
}
