import os

from fastapi import FastAPI

from common_logging import LoggingMiddleware, get_logger, setup_logging
from common_metrics import setup_metrics

setup_logging(log_file=os.getenv("LOG_FILE"))
logger = get_logger("tax")

app = FastAPI(title='Tax Service API')
app.add_middleware(LoggingMiddleware)
setup_metrics(app, "tax-accelerator")

@app.on_event('startup')
async def startup_event():
    logger.info("Tax Service API starting up")

@app.on_event('shutdown')
async def shutdown_event():
    logger.info("Tax Service API shutting down")

@app.get('/')
def root():
    return {'service': 'tax', 'status': 'running'}

@app.get('/health')
def health():
    return {'status': 'healthy'}
