from typing import Any, List, Optional
from datetime import datetime

from fastapi import APIRouter, Body, Depends, HTTPException, Form, status, Response
from fastapi.encoders import jsonable_encoder
from pydantic.networks import EmailStr
from sqlalchemy.orm import Session

from app import crud, models, schemas
from app.api import deps
from app.core.config import settings
from app.core.ecpay_payment_sdk import ECPayPaymentSdk
from app.utils import send_new_account_email

import requests

router = APIRouter()

@router.post("/ecpay-result-return")
def ecpay_return(
    *,
    MerchantID: Optional[str]=Form(None),
    MerchantTradeNo: Optional[str]=Form(None),
    StoreID: Optional[str]=Form(None),
    RtnCode: Optional[int]=Form(None),
    RtnMsg: Optional[str]=Form(None),
    TradeNo: Optional[str]=Form(None),
    TradeAmt: Optional[int]=Form(None),
    PaymentDate: Optional[str]=Form(None),
    PaymentType: Optional[str]=Form(None),
    PaymentTypeChargeFee: Optional[int]=Form(None),
    TradeDate: Optional[str]=Form(None),
    SimulatePaid: Optional[int]=Form(None),
    CustomField1: Optional[str]=Form(None),
    CustomField2: Optional[str]=Form(None),
    CustomField3: Optional[str]=Form(None),
    CustomField4: Optional[str]=Form(None),
    CheckMacValue: Optional[str]=Form(None),
) -> Any:
  #送email
  print(f"\
MerchantID: {MerchantID} \n\
MerchantTradeNo: {MerchantTradeNo}\n\
StoreID: {StoreID}\n\
RtnCode: {RtnCode}\n\
RtnMsg: {RtnMsg}\n\
TradeNo: {TradeNo}\n\
TradeAmt: {TradeAmt}\n\
PaymentDate: {PaymentDate}\n\
PaymentType: {PaymentType}\n\
PaymentTypeChargeFee: {PaymentTypeChargeFee}\n\
TradeDate: {TradeDate}\n\
SimulatePaid: {SimulatePaid}\n\
CustomField1: {CustomField1}\n\
CustomField2: {CustomField2}\n\
CustomField3: {CustomField3}\n\
CustomField4: {CustomField4}\n\
CheckMacValue: {CheckMacValue}\
  ")
  return Response(content='1', status_code=status.HTTP_200_OK)

@router.post("/ecpay-test-result-return")
def ecpay_return(
    *,
    MerchantID: Optional[str]=Form(None),
    MerchantTradeNo: Optional[str]=Form(None),
    StoreID: Optional[str]=Form(None),
    RtnCode: Optional[int]=Form(None),
    RtnMsg: Optional[str]=Form(None),
    TradeNo: Optional[str]=Form(None),
    TradeAmt: Optional[int]=Form(None),
    PaymentDate: Optional[str]=Form(None),
    PaymentType: Optional[str]=Form(None),
    PaymentTypeChargeFee: Optional[int]=Form(None),
    TradeDate: Optional[str]=Form(None),
    SimulatePaid: Optional[int]=Form(None),
    CustomField1: Optional[str]=Form(None),
    CustomField2: Optional[str]=Form(None),
    CustomField3: Optional[str]=Form(None),
    CustomField4: Optional[str]=Form(None),
    CheckMacValue: Optional[str]=Form(None),
) -> Any:
  #送email
  print(f"\
MerchantID: {MerchantID} \n\
MerchantTradeNo: {MerchantTradeNo}\n\
StoreID: {StoreID}\n\
RtnCode: {RtnCode}\n\
RtnMsg: {RtnMsg}\n\
TradeNo: {TradeNo}\n\
TradeAmt: {TradeAmt}\n\
PaymentDate: {PaymentDate}\n\
PaymentType: {PaymentType}\n\
PaymentTypeChargeFee: {PaymentTypeChargeFee}\n\
TradeDate: {TradeDate}\n\
SimulatePaid: {SimulatePaid}\n\
CustomField1: {CustomField1}\n\
CustomField2: {CustomField2}\n\
CustomField3: {CustomField3}\n\
CustomField4: {CustomField4}\n\
CheckMacValue: {CheckMacValue}\
  ")
  return Response(content='1', status_code=status.HTTP_200_OK)


@router.get('/check-payment-list')
def get_payment_list(
  *,
  db: Session = Depends(deps.get_db),
  current_user: models.User = Depends(deps.get_current_active_user)
):
  pass