# -*- coding: utf-8 -*-
"""业务层 · 财务服务（OPC 收支流水）。

业务层只处理业务逻辑，依赖基础设施层 Repository；不反向依赖接口层。
"""
from __future__ import annotations

from ..infrastructure.repositories import Database


class FinanceService:
    """OPC 财务流水管理。"""

    def __init__(self, db: Database):
        self.db = db

    async def add_record(self, user_id: str, category: str, amount: int, date: str, note: str = "") -> dict:
        """记一笔收支（收入为正、支出为负由调用方给定金额符号）。"""
        return await self.db.finance.create(
            user_id=user_id, category=category, amount=amount,
            date=date, note=note,
        )

    async def list_by_user(self, user_id: str, category: str | None = None) -> list[dict]:
        return await self.db.finance.list_by_user(user_id, category)
