import { describe, expect, it } from 'vitest'
import { capturePaypalSchema, chargeSchema, manualPaymentSchema, paymentParamSchema, refundSchema, reservationParamSchema } from './payment.schemas'

describe('payment schemas edge cases', () => {
  it('defaults charge and manual payment currency/type while rejecting unsupported providers', () => {
    expect(chargeSchema.parse({ provider: 'PAYPAL', successUrl: 'https://ok.example.test', failureUrl: 'https://fail.example.test' })).toMatchObject({
      provider: 'PAYPAL',
      type: 'CHARGE',
      currency: 'MAD',
    })
    expect(chargeSchema.safeParse({ provider: 'STRIPE', successUrl: 'https://ok.example.test', failureUrl: 'https://fail.example.test' }).success).toBe(false)
    expect(manualPaymentSchema.parse({ amount: 500, paymentMethod: 'CASH' })).toMatchObject({ amount: 500, currency: 'MAD', type: 'CHARGE' })
    expect(manualPaymentSchema.safeParse({ amount: 0, paymentMethod: 'CASH' }).success).toBe(false)
  })

  it('validates refund/capture/payment parameter payloads', () => {
    expect(refundSchema.parse({})).toEqual({})
    expect(refundSchema.safeParse({ amount: -1 }).success).toBe(false)
    expect(capturePaypalSchema.safeParse({ paypalOrderId: 'order_1' }).success).toBe(true)
    expect(capturePaypalSchema.safeParse({}).success).toBe(false)
    expect(reservationParamSchema.safeParse({ id: '' }).success).toBe(false)
    expect(paymentParamSchema.safeParse({ reservationId: 'reservation_1', paymentId: 'payment_1' }).success).toBe(true)
  })
})
