#!/usr/bin/env python3
"""Minimal aiogram 3 appointment booking bot template."""
import asyncio, logging, sqlite3
from aiogram import Bot, Dispatcher, F
from aiogram.filters import Command
from aiogram.types import Message

DB='bookings.db'
def init_db():
    con=sqlite3.connect(DB); con.execute('CREATE TABLE IF NOT EXISTS bookings(id INTEGER PRIMARY KEY, user_id INTEGER, slot TEXT, UNIQUE(slot))'); con.commit(); return con
async def start(msg: Message):
    await msg.answer('Send /book 2026-09-01T10:00 to book a slot.')
async def book(msg: Message):
    slot=msg.text.split(maxsplit=1)[1] if len(msg.text.split(maxsplit=1))>1 else ''
    if not slot: await msg.answer('Usage: /book <slot>'); return
    con=init_db()
    try:
        con.execute('INSERT INTO bookings(user_id, slot) VALUES(?,?)',(msg.from_user.id, slot)); con.commit(); await msg.answer('Booked.')
    except sqlite3.IntegrityError:
        await msg.answer('Slot unavailable.')
async def main():
    bot=Bot(token='YOUR_BOT_TOKEN'); dp=Dispatcher(); init_db()
    dp.message.register(start, Command('start')); dp.message.register(book, Command('book'))
    await dp.start_polling(bot)
if __name__=='__main__':
    asyncio.run(main())
