import client from './client'
import type {
  PromoCode,
  PromoCodeCreate,
  PromoCodeUpdate,
  PromoCodeRedemption,
  PromoCodeRedeemResponse,
} from '@/types'

export const promoApi = {
  // User endpoint - redeem promo code
  redeem: (code: string) =>
    client.post<PromoCodeRedeemResponse>('/promo/redeem', { code }),

  // Admin endpoints
  admin: {
    list: (includeInactive = false) =>
      client.get<PromoCode[]>('/promo/admin/list', {
        params: { include_inactive: includeInactive },
      }),

    create: (data: PromoCodeCreate) =>
      client.post<PromoCode>('/promo/admin/create', data),

    update: (id: number, data: PromoCodeUpdate) =>
      client.put<PromoCode>(`/promo/admin/${id}`, data),

    delete: (id: number) =>
      client.delete<{ message: string }>(`/promo/admin/${id}`),

    getRedemptions: (id: number) =>
      client.get<PromoCodeRedemption[]>(`/promo/admin/${id}/redemptions`),
  },
}
