from fastapi import APIRouter
from app.core.database import get_connection

router = APIRouter(prefix="/accounts", tags=["科目"])

@router.get("", summary="科目一覧取得")
def get_accounts():
    """
    科目マスタ一覧を返す
    """
    with get_connection() as conn, conn.cursor() as cur:
        cur.execute("""
            SELECT
                account_id,
                account_code,
                account_name,
                account_type
            FROM accounts
            ORDER BY account_code
        """)
        rows = cur.fetchall()

    return rows
