package com.devlab.app.data.repository

import com.devlab.app.data.api.RetrofitClient
import com.devlab.app.data.model.*

class ServerRepository {

    private val api get() = RetrofitClient.getApiService()

    suspend fun getServers(page: Int = 1, perPage: Int = 20, search: String? = null): ApiResponse<List<Server>> {
        return api.getServers(page, perPage, search)
    }

    suspend fun getServerDetail(id: Int): ApiResponse<ServerDetail> {
        return api.getServerDetail(id)
    }

    suspend fun getServerMetrics(id: Int, hours: Int = 24): ApiResponse<List<MetricPoint>> {
        return api.getServerMetrics(id, hours)
    }

    suspend fun executeCommand(id: Int, command: String): ApiResponse<CommandResult> {
        return api.executeCommand(id, CommandRequest(command))
    }

    suspend fun getServerServices(id: Int): ApiResponse<List<ServiceInfo>> {
        return api.getServerServices(id)
    }

    suspend fun rebootServer(id: Int): ApiResponse<Map<String, String>> {
        return api.serverReboot(id)
    }

    suspend fun shutdownServer(id: Int): ApiResponse<Map<String, String>> {
        return api.serverShutdown(id)
    }

    suspend fun testConnection(id: Int): ApiResponse<ConnectionResult> {
        return api.testServerConnection(id)
    }

    suspend fun serviceAction(id: Int, service: String, action: String): ApiResponse<ServiceActionResult> {
        return api.serviceAction(id, ServiceActionRequest(service, action))
    }
}
