-- Migration 063: Paid events — payment tracking for event attendees and guests
-- Date: 2026-04-08

-- NordaEvent: paid event fields
ALTER TABLE norda_events ADD COLUMN IF NOT EXISTS is_paid BOOLEAN DEFAULT FALSE;
ALTER TABLE norda_events ADD COLUMN IF NOT EXISTS price_member NUMERIC(10,2);
ALTER TABLE norda_events ADD COLUMN IF NOT EXISTS price_guest NUMERIC(10,2);

-- EventAttendee: payment tracking
ALTER TABLE event_attendees ADD COLUMN IF NOT EXISTS payment_status VARCHAR(20) DEFAULT 'unpaid';
ALTER TABLE event_attendees ADD COLUMN IF NOT EXISTS payment_amount NUMERIC(10,2);
ALTER TABLE event_attendees ADD COLUMN IF NOT EXISTS payment_confirmed_by INTEGER REFERENCES users(id);
ALTER TABLE event_attendees ADD COLUMN IF NOT EXISTS payment_confirmed_at TIMESTAMP;

-- EventGuest: payment tracking
ALTER TABLE event_guests ADD COLUMN IF NOT EXISTS payment_status VARCHAR(20) DEFAULT 'unpaid';
ALTER TABLE event_guests ADD COLUMN IF NOT EXISTS payment_amount NUMERIC(10,2);
ALTER TABLE event_guests ADD COLUMN IF NOT EXISTS payment_confirmed_by INTEGER REFERENCES users(id);
ALTER TABLE event_guests ADD COLUMN IF NOT EXISTS payment_confirmed_at TIMESTAMP;

-- Grants for app user
GRANT ALL ON TABLE norda_events TO nordabiz_app;
GRANT ALL ON TABLE event_attendees TO nordabiz_app;
GRANT ALL ON TABLE event_guests TO nordabiz_app;

-- Set grill event as paid
UPDATE norda_events SET is_paid = true, price_member = 140, price_guest = 240 WHERE id = 57;
