package com.carmaintenance.data.repository

import com.carmaintenance.data.model.Vehicle
import com.carmaintenance.data.remote.ApiResponse
import com.carmaintenance.data.remote.ApiService
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class VehicleRepository @Inject constructor(
    private val apiService: ApiService
) {
    suspend fun getVehicles(): Result<List<Vehicle>> {
        return try {
            val response = apiService.getVehicles()
            if (response.isSuccess) {
                Result.success(response.data ?: emptyList())
            } else {
                Result.failure(Exception(response.message ?: "获取车辆列表失败"))
            }
        } catch (e: Exception) {
            Result.failure(e)
        }
    }

    suspend fun getCustomerVehicles(customerId: Int): Result<List<Vehicle>> {
        return try {
            val response = apiService.getVehiclesByCustomer(customerId)
            if (response.isSuccess) {
                Result.success(response.data ?: emptyList())
            } else {
                Result.failure(Exception(response.message ?: "获取车辆列表失败"))
            }
        } catch (e: Exception) {
            Result.failure(e)
        }
    }
}
