import { When, Given } from '@cucumber/cucumber' import type { PerausetWorld } from '../support/world.js' import { openDb } from '../support/db.js' When('I create a room with code {string} name {string} type {string} capacity {int}', async function (this: PerausetWorld, code: string, name: string, roomType: string, capacity: number) { await this.post('/rooms', { code, name, roomType, capacity, }) }) When('I allocate the room to the stay from {string} to {string}', async function (this: PerausetWorld, startsAt: string, endsAt: string) { const roomId = (this as any).roomId const stayId = (this as any).stayId await this.post('/rooms/allocations', { roomId, stayId, startsAt, endsAt, }) }) When('I allocate the room to stored stay {string} from {string} to {string}', async function (this: PerausetWorld, stayKey: string, startsAt: string, endsAt: string) { const roomId = (this as any).roomId const stayId = (this as any)[stayKey] await this.post('/rooms/allocations', { roomId, stayId, startsAt, endsAt, }) }) Given('the room allocation is active in the database', async function (this: PerausetWorld) { const allocationId = (this as any).allocationId const db = openDb() try { db.prepare(`UPDATE room_allocation SET status = 'active' WHERE allocation_id = ?`).run(allocationId) } finally { db.close() } }) When('I release the room allocation', async function (this: PerausetWorld) { const allocationId = (this as any).allocationId await this.post(`/rooms/allocations/${allocationId}/release`, { allocationId, }) })