from __future__ import annotations

from fastapi import APIRouter, status

from app.core.bootstrap import build_bootstrap_state, persist_bootstrap_config
from app.core.config import get_settings
from app.schemas.bootstrap import BootstrapSetupPayload, BootstrapStateRead

router = APIRouter(prefix="/bootstrap")


@router.get("", response_model=BootstrapStateRead)
def get_bootstrap_state() -> BootstrapStateRead:
    return build_bootstrap_state(get_settings())


@router.post("", response_model=BootstrapStateRead, status_code=status.HTTP_201_CREATED)
def initialize_bootstrap(payload: BootstrapSetupPayload) -> BootstrapStateRead:
    return persist_bootstrap_config(payload, get_settings())
