import { Reservation, Settings } from '@backend/domain'
import { ICSService } from './ics.service'

const settings = {
	customerApp: { displayName: 'Testhaus' },
	restaurant: { address: 'Weg 1', email: 'info@x.de' },
} as unknown as Settings

const reservation = {
	id: 'uid-123',
	startDate: new Date('2099-06-01T17:30:00Z'),
	endDate: new Date('2099-06-01T19:30:00Z'),
	customerData: { name: 'Maxi', email: 'maxi@example.com' },
} as unknown as Reservation

describe('ICSService', () => {
	const service = new ICSService()

	it('produces a REQUEST invite by default', () => {
		const ics = service.generateIcs(reservation, settings)
		expect(ics).toContain('METHOD:REQUEST')
		expect(ics).toContain('STATUS:CONFIRMED')
		expect(ics).toContain('SEQUENCE:0')
		expect(ics).toContain('UID:uid-123')
	})

	it('produces a CANCEL with same UID and bumped sequence so calendars remove the event', () => {
		const ics = service.generateIcs(reservation, settings, { cancelled: true })
		expect(ics).toContain('METHOD:CANCEL')
		expect(ics).toContain('STATUS:CANCELLED')
		expect(ics).toContain('SEQUENCE:1')
		expect(ics).toContain('UID:uid-123')
	})
})
