import { ISession } from "../../Models/Session.model";
import { connect } from "mongoose";

import {
    LoginParams,
    LoginByTokenParams,
    LoginByGoogleParams,
    VerificationUserParams,
} from "../../Models/Users/Users.Interface";
import UsersManager from "../../Models/Users/Users";
export class LoginService {
    /**
     * Asynchronously logs in a user.
     *
     * @param {LoginParams} data - The login parameters.
     * @return {Promise<ISession>} The session object.
     */
    public async login(data: LoginParams): Promise<ISession> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return UsersManager.login(data);
    }

    /**
     * Logs in a user using a token.
     * @param {LoginByTokenParams} params - The parameters for logging in.
     * @returns {Promise<ISession>} - The session object.
     * @throws {Error} - If the token is invalid.
     */
    public async loginByToken({ token }: LoginByTokenParams): Promise<ISession> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return UsersManager.loginByToken({ token });
    }

    public async loginByGoogle({ token }: LoginByGoogleParams): Promise<ISession> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return UsersManager.loginByGoogle({ token });
    }

    public async loginByAndroid({ token }: LoginByGoogleParams): Promise<ISession> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return UsersManager.loginByAndroid({ token });
    }

    public async verificateAndLoginUser(data: VerificationUserParams): Promise<ISession> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return UsersManager.verificateAndLoginUser(data);
    }
}
