// src/server/services/auth_service.rs
use tonic::{Request, Response, Status};
use common::proto::komp_ac::auth::{
    auth_service_server::AuthService,
    RegisterRequest, AuthResponse,
    LoginRequest, LoginResponse
};
use crate::auth::handlers::{
    login::login,
    register::register
};
use sqlx::PgPool;

#[derive(Debug)]
pub struct AuthServiceImpl {
    pub db_pool: PgPool,
}

#[tonic::async_trait]
impl AuthService for AuthServiceImpl {
    async fn register(
        &self,
        request: Request<RegisterRequest>,
    ) -> Result<Response<AuthResponse>, Status> {
        let response = register(&self.db_pool, request.into_inner()).await?;
        Ok(response)
    }

    async fn login(
        &self,
        request: Request<LoginRequest>,
    ) -> Result<Response<LoginResponse>, Status> {
        let response = login(&self.db_pool, request.into_inner()).await?;
        Ok(response)
    }
}
