import logging

from app.services.payment.base import PaymentGateway, PaymentOrder, PaymentCallback

logger = logging.getLogger(__name__)


class MockGateway(PaymentGateway):
    async def create_order(
        self, order_id: str, amount: float, description: str, user_id: str, plan: str
    ) -> PaymentOrder:
        logger.info(f"[MockPayment] 创建订单: order_id={order_id}, amount={amount}, plan={plan}")
        return PaymentOrder(
            order_id=order_id,
            pay_url=f"mock://pay/{order_id}",
            amount=amount,
            status="pending",
        )

    async def verify_callback(self, request_data: dict) -> PaymentCallback:
        order_id = request_data.get("order_id", request_data.get("out_trade_no", ""))
        logger.info(f"[MockPayment] 验证回调: order_id={order_id}")
        return PaymentCallback(
            order_id=order_id,
            payment_id=f"mock_pay_{order_id}",
            amount=float(request_data.get("amount", 0)),
            status="success",
            raw_data=request_data,
        )

    async def query_order(self, order_id: str) -> PaymentOrder:
        logger.info(f"[MockPayment] 查询订单: order_id={order_id}")
        return PaymentOrder(
            order_id=order_id,
            pay_url=f"mock://pay/{order_id}",
            amount=0,
            status="completed",
        )

    async def refund(self, order_id: str, amount: float, reason: str = "") -> bool:
        logger.info(f"[MockPayment] 退款: order_id={order_id}, amount={amount}, reason={reason}")
        return True
