import { describe, expect, it, vi } from 'vitest'

vi.mock('../../lib/prisma', () => ({ prisma: {} }))
vi.mock('../../lib/redis', () => ({
  redis: { on: vi.fn(), get: vi.fn(), set: vi.fn(), del: vi.fn(), quit: vi.fn() },
}))
vi.mock('../../middleware/requireRenterAuth', () => ({
  requireRenterAuth: (_req: any, _res: any, next: any) => next(),
  optionalRenterAuth: (_req: any, _res: any, next: any) => next(),
}))
vi.mock('../../modules/site/site.service', () => ({
  getPlatformHomepage: vi.fn(),
  getPlatformPricing: vi.fn(),
  getBrand: vi.fn(),
  getPublicVehicles: vi.fn(),
  getVehicleDetail: vi.fn(),
  getOffers: vi.fn(),
  getBookingOptions: vi.fn(),
  checkAvailability: vi.fn(),
  validatePromoCode: vi.fn(),
  createBooking: vi.fn(),
  getBooking: vi.fn(),
  initPayment: vi.fn(),
  capturePaypal: vi.fn(),
  handleContact: vi.fn(),
}))
vi.mock('../../modules/carplace/carplace.service', () => ({
  getPublicOffers: vi.fn(),
  getCities: vi.fn(),
  getListedCompanies: vi.fn(),
  searchVehicles: vi.fn(),
  createCarplaceReservation: vi.fn(),
  getReviewContext: vi.fn(),
  submitReview: vi.fn(),
  validateOfferCode: vi.fn(),
  getCompanyPage: vi.fn(),
  getCompanyReviews: vi.fn(),
  getCompanyVehicles: vi.fn(),
  getVehicleDetail: vi.fn(),
  getCompanyOffers: vi.fn(),
}))

import request from 'supertest'
import { createApp } from '../../app'
import * as siteService from '../../modules/site/site.service'
import * as carplaceService from '../../modules/carplace/carplace.service'

const app = createApp()

describe('public validation e2e smoke', () => {
  it('rejects bad anonymous booking, payment, and review payloads without crossing service boundaries', async () => {
    const booking = await request(app).post('/api/v1/site/atlas-cars/book').send({ email: 'not-enough' })
    expect(booking.status).toBe(400)
    expect(siteService.createBooking).not.toHaveBeenCalled()

    const payment = await request(app).post('/api/v1/site/atlas-cars/booking/reservation_1/pay').send({
      provider: 'PAYPAL',
      successUrl: 'not-a-url',
      failureUrl: 'also-not-a-url',
    })
    expect(payment.status).toBe(400)
    expect(siteService.initPayment).not.toHaveBeenCalled()

    const review = await request(app).post('/api/v1/carplace/review/token_1').send({ overallRating: 0 })
    expect(review.status).toBe(400)
    expect(carplaceService.submitReview).not.toHaveBeenCalled()
  })
})
