import emitter from '@adonisjs/core/services/emitter';
import { DateTime } from 'luxon';
export const authService = (userServiceClass, jwtService) => {
    const userService = new userServiceClass();
    return class AKAuthService {
        async createTokens(user) {
            const access_token = await jwtService.accessToken(user);
            const refresh_token = await jwtService.refreshToken(user);
            return {
                access_token,
                refresh_token,
            };
        }
        async signup(email, password, userData) {
            const user = await userService.signup(email, password, userData);
            const { access_token, refresh_token } = await this.createTokens(user);
            return {
                user,
                access_token,
                refresh_token,
            };
        }
        async login(email, password) {
            const user = await userService.login(email, password);
            const { access_token, refresh_token } = await this.createTokens(user);
            return {
                user,
                access_token,
                refresh_token,
            };
        }
        async forgotPassword(email) {
            const user = await await userService.findByEmail(email);
            if (user)
                await emitter.emit('auth.forgot_password', user);
            return user !== undefined;
        }
        async setPassword(user, password) {
            await userService.updatePassword(user, password);
        }
        async delete(user, password, reason) {
            await userService.login(user.email, password);
            user.disabledAt = DateTime.now();
            user.disabledReason = reason;
            await user.save();
        }
    };
};
//# sourceMappingURL=auth_service.js.map