import { Injectable } from '@nestjs/common';
import { UsersRepository } from './users.repository';
import type { User, UserClaims } from './user.types';

@Injectable()
export class UsersService {
  constructor(private readonly usersRepository: UsersRepository) {}

  findOrCreateByExternalSubjectId(
    externalSubjectId: string,
    claims: UserClaims,
  ): Promise<User> {
    return this.usersRepository.upsertByExternalSubjectId(
      externalSubjectId,
      claims,
    );
  }

  findById(id: string): Promise<User | undefined> {
    return this.usersRepository.findById(id);
  }
}
