"""Generated by Drydock from DATABASE.md. Do not edit; edit the declaration and rebuild.

This module is the declared persistence contract as Python: the tables, the operations each
Blueprint cites, and the row a read or a create returns. It contains no SQL — statements are built by the
driver for the engine in use, so a parameter placeholder never appears here.
"""

from __future__ import annotations

from dataclasses import dataclass

from .db import Database, Operation, Schema, Table

__all__ = ["SCHEMA", "open_database", "AccountBalanceRow", "AccountRow", "CategoryRow", "ReportRow", "SchemaStatus", "TransactionRow"]

@dataclass(frozen=True)
class SchemaStatus:
    tables: str


@dataclass(frozen=True)
class AccountRow:
    account: str
    name: str


@dataclass(frozen=True)
class CategoryRow:
    category: str
    description: str


@dataclass(frozen=True)
class TransactionRow:
    txn_id: int
    date: str
    account: str
    category: str
    amount: int
    memo: str


@dataclass(frozen=True)
class AccountBalanceRow:
    account: str
    name: str
    transactions: int
    balance: int


@dataclass(frozen=True)
class ReportRow:
    values: str


SCHEMA = Schema(
    tables=(
        Table(name='accounts', columns=('account', 'name'), primary_key='account'),
        Table(name='categories', columns=('category', 'description'), primary_key='category'),
        Table(name='transactions', columns=('txn_id', 'date', 'account', 'category', 'amount', 'memo'), primary_key='txn_id'),
    ),
    operations=(
    Operation(
        identifier='FEATURE-DB-001',
        table='accounts',
        verb='create',
        inputs=('drop_existing',),
        row=SchemaStatus,
        columns=('account', 'name'),
    ),
    Operation(
        identifier='FEATURE-DB-002',
        table='accounts',
        verb='create',
        inputs=('account', 'name'),
        row=AccountRow,
        columns=('account', 'name'),
    ),
    Operation(
        identifier='FEATURE-DB-003',
        table='categories',
        verb='create',
        inputs=('category', 'description'),
        row=CategoryRow,
        columns=('category', 'description'),
    ),
    Operation(
        identifier='FEATURE-DB-004',
        table='transactions',
        verb='create',
        inputs=('txn_id', 'date', 'account', 'category', 'amount', 'memo'),
        row=TransactionRow,
        columns=('txn_id', 'date', 'account', 'category', 'amount', 'memo'),
    ),
    Operation(
        identifier='FEATURE-DB-005',
        table='accounts',
        verb='get',
        inputs=('account',),
        row=AccountRow,
        columns=('account', 'name'),
    ),
    Operation(
        identifier='FEATURE-DB-006',
        table='transactions',
        verb='get',
        inputs=('txn_id',),
        row=TransactionRow,
        columns=('txn_id', 'date', 'account', 'category', 'amount', 'memo'),
    ),
    Operation(
        identifier='FEATURE-DB-007',
        table='accounts',
        verb='list',
        inputs=('report',),
        row=AccountRow,
        columns=('account', 'name'),
    ),
    Operation(identifier='FEATURE-DB-008', table='categories', verb='list', inputs=('report',), row=CategoryRow, columns=('category', 'description')),
    Operation(identifier='FEATURE-DB-009', table='transactions', verb='list', inputs=('report',), row=TransactionRow, columns=('txn_id', 'date', 'account', 'category', 'amount', 'memo')),
    Operation(identifier='FEATURE-DB-010', table='accounts', verb='update', inputs=('account', 'name'), key='account'),
    Operation(identifier='FEATURE-DB-011', table='transactions', verb='update', inputs=('txn_id', 'amount'), key='txn_id'),
    Operation(identifier='FEATURE-DB-012', table='accounts', verb='delete', inputs=('account',), key='account'),
    Operation(identifier='FEATURE-DB-013', table='transactions', verb='delete', inputs=('txn_id',), key='txn_id'),
    ),
)


def open_database(dsn: str) -> Database:
    """Open the declared store. The engine is selected from the DSN, not from the build."""
    return Database(dsn, SCHEMA)
