package lu.rewardflow.terminal.data.api

import lu.rewardflow.terminal.data.model.*
import retrofit2.http.*

/**
 * Retrofit interface for the Orion Loyalty Store API.
 *
 * Mirrors the endpoints at /api/v1/store/loyalty/
 * Auth via Bearer token (obtained during device setup).
 */
interface LoyaltyApi {

    // Program
    @GET("api/v1/store/loyalty/program")
    suspend fun getProgram(): ProgramResponse

    // Card Lookup
    @GET("api/v1/store/loyalty/cards/lookup")
    suspend fun lookupCard(@Query("q") query: String): CardLookupResponse

    @GET("api/v1/store/loyalty/cards/{cardId}")
    suspend fun getCardDetail(@Path("cardId") cardId: Int): CardDetailResponse

    // Enrollment
    @POST("api/v1/store/loyalty/cards/enroll")
    suspend fun enrollCustomer(@Body request: EnrollRequest): CardResponse

    // Stamps
    @POST("api/v1/store/loyalty/stamp")
    suspend fun addStamp(@Body request: StampRequest): StampResponse

    @POST("api/v1/store/loyalty/stamp/redeem")
    suspend fun redeemStamps(@Body request: StampRedeemRequest): StampRedeemResponse

    // Points
    @POST("api/v1/store/loyalty/points/earn")
    suspend fun earnPoints(@Body request: PointsEarnRequest): PointsEarnResponse

    @POST("api/v1/store/loyalty/points/redeem")
    suspend fun redeemPoints(@Body request: PointsRedeemRequest): PointsRedeemResponse

    // PINs (for caching staff PINs locally)
    @GET("api/v1/store/loyalty/pins")
    suspend fun listPins(): PinListResponse

    /**
     * PINs with their bcrypt pin_hash. Only callable with a paired-device
     * JWT — user JWTs receive 403. Used by the tablet to verify staff
     * PINs offline.
     */
    @GET("api/v1/store/loyalty/pins/for-device")
    suspend fun listPinsForDevice(): PinForDeviceListResponse

    // Categories (for the action sheets — multi-select pills)
    @GET("api/v1/store/loyalty/categories")
    suspend fun listCategories(): CategoryListResponse

    // Recent transactions for the merchant — used in the terminal screen's
    // left-pane "Recent Transactions" panel.
    @GET("api/v1/store/loyalty/transactions")
    suspend fun listRecentTransactions(
        @Query("skip") skip: Int = 0,
        @Query("limit") limit: Int = 10,
    ): TransactionListResponse

    // Auth
    @POST("api/v1/store/auth/login")
    suspend fun login(@Body request: LoginRequest): LoginResponse
}
