-- Add club_uuid to courts table
ALTER TABLE courts ADD COLUMN IF NOT EXISTS club_uuid UUID;
ALTER TABLE courts ADD COLUMN IF NOT EXISTS description TEXT;
ALTER TABLE courts ADD CONSTRAINT fk_courts_club
    FOREIGN KEY (club_uuid) REFERENCES tennis_clubs(uuid) ON DELETE CASCADE;
CREATE INDEX IF NOT EXISTS idx_courts_club_uuid ON courts(club_uuid);

-- Add contact/social fields to tennis_clubs
ALTER TABLE tennis_clubs ADD COLUMN IF NOT EXISTS contact_phone TEXT;
ALTER TABLE tennis_clubs ADD COLUMN IF NOT EXISTS contact_person TEXT;
ALTER TABLE tennis_clubs ADD COLUMN IF NOT EXISTS telegram_link TEXT;

-- Court booking requests
CREATE TABLE IF NOT EXISTS court_booking_requests (
    uuid         UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    club_uuid    UUID NOT NULL,
    court_uuid   UUID,
    court_name   TEXT,
    requester_name  TEXT NOT NULL,
    requester_email TEXT NOT NULL,
    requester_phone TEXT,
    booking_date DATE NOT NULL,
    start_time   TIME NOT NULL,
    end_time     TIME NOT NULL,
    message      TEXT,
    status       TEXT NOT NULL DEFAULT 'NEW',
    created_at   TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT fk_booking_club FOREIGN KEY (club_uuid)
        REFERENCES tennis_clubs(uuid) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_booking_club ON court_booking_requests(club_uuid);
