import type { AuthRepository } from '@ports/AuthRepository'; import type { AuthSession, LoginInput, RegisterInput, GoogleOAuthInput } from '@domain/User'; /** * Caso de uso: Login com e-mail/senha. */ export class LoginUseCase { constructor(private readonly authRepo: AuthRepository) {} async execute(input: LoginInput): Promise { if (!input.email || !input.password) { throw new Error('E-mail e senha são obrigatórios.'); } return this.authRepo.login(input); } } /** * Caso de uso: Cadastro de novo usuário. */ export class RegisterUseCase { constructor(private readonly authRepo: AuthRepository) {} async execute(input: RegisterInput): Promise { if (!input.email || !input.password) { throw new Error('E-mail e senha são obrigatórios.'); } if (input.password.length < 8) { throw new Error('A senha deve ter ao menos 8 caracteres.'); } await this.authRepo.register(input); } } /** * Caso de uso: Login via OAuth Google. */ export class GoogleLoginUseCase { constructor(private readonly authRepo: AuthRepository) {} async execute(input: GoogleOAuthInput): Promise { return this.authRepo.loginWithGoogle(input); } } /** * Caso de uso: Logout. */ export class LogoutUseCase { constructor(private readonly authRepo: AuthRepository) {} async execute(accessToken: string): Promise { await this.authRepo.logout(accessToken); } } /** * Caso de uso: Reenviar e-mail de verificação de conta. */ export class ResendVerificationUseCase { constructor(private readonly authRepo: AuthRepository) {} async execute(email: string): Promise { if (!email) throw new Error('E-mail obrigatório.'); await this.authRepo.resendVerification(email); } } /** * Caso de uso: Solicitar redefinição de senha. */ export class ForgotPasswordUseCase { constructor(private readonly authRepo: AuthRepository) {} async execute(email: string): Promise { await this.authRepo.forgotPassword(email); } } /** * Caso de uso: Verificar e-mail com token recebido por deep link. */ export class VerifyEmailUseCase { constructor(private readonly authRepo: AuthRepository) {} async execute(token: string): Promise { if (!token) throw new Error('Token inválido.'); await this.authRepo.verifyEmail(token); } } /** * Caso de uso: Redefinir senha com token. */ export class ResetPasswordUseCase { constructor(private readonly authRepo: AuthRepository) {} async execute(token: string, newPassword: string): Promise { if (newPassword.length < 8) { throw new Error('A nova senha deve ter ao menos 8 caracteres.'); } await this.authRepo.resetPassword(token, newPassword); } }