import { describe, expect, it } from 'vitest'
import { offerSchema, listQuerySchema } from './offer.schemas'

const validOffer = {
  title: 'Summer deal',
  type: 'PERCENTAGE',
  discountValue: 15,
  validFrom: '2026-07-01T00:00:00.000Z',
  validUntil: '2026-07-31T23:59:59.000Z',
}

describe('offer schemas', () => {
  it('applies safe defaults for public all-fleet offers', () => {
    expect(offerSchema.parse(validOffer)).toMatchObject({
      appliesToAll: true,
      categories: [],
      vehicleIds: [],
      isActive: true,
      isPublic: true,
      isFeatured: false,
    })
  })

  it('accepts targeted vehicle and category offers', () => {
    expect(offerSchema.parse({
      ...validOffer,
      appliesToAll: false,
      categories: ['SUV', 'LUXURY'],
      vehicleIds: ['vehicle_1', 'vehicle_2'],
    })).toMatchObject({ appliesToAll: false, categories: ['SUV', 'LUXURY'], vehicleIds: ['vehicle_1', 'vehicle_2'] })
  })

  it('rejects non-integer discounts and malformed dates', () => {
    expect(() => offerSchema.parse({ ...validOffer, discountValue: 12.5 })).toThrow()
    expect(() => offerSchema.parse({ ...validOffer, validFrom: 'tomorrow' })).toThrow()
  })

  it('keeps list filters as strings because route logic interprets them', () => {
    expect(listQuerySchema.parse({ active: 'true', public: 'false' })).toEqual({ active: 'true', public: 'false' })
  })
})
