// src/server/services/table_script_service.rs
use tonic::{Request, Response, Status};
use common::proto::komp_ac::table_script::{
    table_script_server::TableScript,
    PostTableScriptRequest, TableScriptResponse
};
use crate::table_script::handlers::post_table_script;
use sqlx::PgPool;

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

#[tonic::async_trait]
impl TableScript for TableScriptService {
    async fn post_table_script(
        &self,
        request: Request<PostTableScriptRequest>,
    ) -> Result<Response<TableScriptResponse>, Status> {
        let request = request.into_inner();
        let response = post_table_script(&self.db_pool, request).await?;
        Ok(Response::new(response))
    }
}
