// src/auth/logic/rbac.rs

use tower::ServiceBuilder;
use crate::auth::logic::rbac;

// TODO redesign this, adresar and uctovnictvo are nonexistent, but we are keeping this code for
// the reference. Please adjust in the future rbac.
pub async fn run_server(db_pool: sqlx::PgPool) -> Result<(), Box<dyn std::error::Error>> {
    // ... existing setup code ...

    // Create service layers
    let adresar_layer = ServiceBuilder::new()
        .layer(rbac::create_adresar_layer())
        .into_inner();

    let uctovnictvo_layer = ServiceBuilder::new()
        .layer(rbac::create_uctovnictvo_layer())
        .into_inner();

    // Create services with layers
    let adresar_service = AdresarServer::new(AdresarService { db_pool: db_pool.clone() })
        .layer(adresar_layer);

    let uctovnictvo_service = UctovnictvoServer::new(UctovnictvoService { db_pool: db_pool.clone() })
        .layer(uctovnictvo_layer);

    // ... repeat for other services ...

    Server::builder()
        .add_service(auth_server)
        .add_service(adresar_service)
        .add_service(uctovnictvo_service)
        // ... other services ...
        .serve(addr)
        .await?;

    Ok(())
}
