package com.carmaintenance.data.remote

import com.carmaintenance.data.model.*
import retrofit2.http.*

/**
 * API服务接口
 */
interface ApiService {

    // ==================== 认证相关 ====================
    @POST("auth/login")
    suspend fun login(@Body request: LoginRequest): ApiResponse<LoginResponseData>

    @POST("auth/logout")
    suspend fun logout(): ApiResponse<Void>

    // ==================== 用户相关 ====================
    @GET("users")
    suspend fun getUsers(): ApiResponse<List<User>>

    @GET("users/{id}")
    suspend fun getUser(@Path("id") id: Int): ApiResponse<User>

    // ==================== 车辆相关 ====================
    @GET("vehicles")
    suspend fun getVehicles(): ApiResponse<List<Vehicle>>

    @GET("vehicles/{id}")
    suspend fun getVehicle(@Path("id") id: Int): ApiResponse<Vehicle>

    @GET("vehicles/customer/{customerId}")
    suspend fun getVehiclesByCustomer(@Path("customerId") customerId: Int): ApiResponse<List<Vehicle>>

    // ==================== 工单相关 ====================
    @GET("orders")
    suspend fun getOrders(): ApiResponse<List<ServiceOrder>>

    @GET("orders/{id}")
    suspend fun getOrder(@Path("id") id: Int): ApiResponse<ServiceOrder>

    @GET("orders/customer/{customerId}")
    suspend fun getOrdersByCustomer(@Path("customerId") customerId: Int): ApiResponse<List<ServiceOrder>>

    @PUT("orders/{id}")
    suspend fun updateOrder(
        @Path("id") id: Int,
        @Body order: ServiceOrder
    ): ApiResponse<ServiceOrder>

    // ==================== 预约相关 ====================
    @GET("appointments")
    suspend fun getAppointments(): ApiResponse<List<Appointment>>

    @GET("appointments/{id}")
    suspend fun getAppointment(@Path("id") id: Int): ApiResponse<Appointment>

    @GET("appointments/customer/{customerId}")
    suspend fun getAppointmentsByCustomer(@Path("customerId") customerId: Int): ApiResponse<List<Appointment>>

    @POST("appointments")
    suspend fun createAppointment(@Body appointment: Appointment): ApiResponse<Appointment>

    @PUT("appointments/{id}/cancel")
    suspend fun cancelAppointment(@Path("id") id: Int): ApiResponse<Void>

    // ==================== 客户相关 ====================
    @GET("customers")
    suspend fun getCustomers(): ApiResponse<List<Customer>>

    @GET("customers/user/{userId}")
    suspend fun getCustomerByUserId(@Path("userId") userId: Int): ApiResponse<Customer>
}

/**
 * 客户实体
 */
data class Customer(
    @SerializedName("customerId")
    val customerId: Int,
    @SerializedName("userId")
    val userId: Int,
    @SerializedName("customerNo")
    val customerNo: String,
    @SerializedName("idCard")
    val idCard: String? = null,
    @SerializedName("address")
    val address: String? = null,
    @SerializedName("gender")
    val gender: String? = null,
    @SerializedName("birthDate")
    val birthDate: String? = null,
    @SerializedName("membershipLevel")
    val membershipLevel: String? = null,
    @SerializedName("points")
    val points: Int = 0
)
