from fastapi import APIRouter, Form, Depends, HTTPException, Body
from fastapi.security import OAuth2PasswordRequestForm, OAuth2PasswordBearer
from app.models.models import User, UserPydantic,User_information,User_point
from app.api import deps
from sqlalchemy.orm import Session
from typing import Any, Dict, Optional
import secrets
from fastapi_login.exceptions import InvalidCredentialsException
from fastapi_login import LoginManager
from datetime import timedelta,datetime
from app.config import settings
from pathlib import Path
from jose import jwt
import emails
from emails.template import JinjaTemplate
import logging
import bcrypt
import smtplib
from email.mime.text import MIMEText
from google.oauth2 import id_token
from google.auth.transport import requests
from fastapi.openapi.models import OAuthFlows as OAuthFlowsModel
from datetime import timedelta,datetime
from app.log import my_log
from Crypto.Cipher import Blowfish
from Crypto import Random
import requests

user_MOC = APIRouter()

@user_MOC.post("/get_user_data_from_MOC")
async def get_user_data_from_MOC(authCode:str = None):
    try:
        api_url = "https://member.moc.gov.tw/MOCMC/T0001/ottGetAuthToken"

        # 定義請求參數
        params = {
            'SYS_ID': 'CRAFT_NTCRI',
            'SYS_PASSWORD': 'luZ2le0W',
            'AuthCode': '839bd320-14cf-49fd-a52b-63d518256964',
            'IS_DEV': 'Y'
        }


        cert_file_path = '/home/choozmo/certificate.pem'
        key_file_path = '/home/choozmo/private_key.pem'
        cert_files = (cert_file_path, key_file_path)
        ca_cert = '/var/www/ssl/eCA1_GTLSCA.crt'
        # 發送 GET 請求
        response = requests.get(api_url, params=params)
        # 定義 API 網址
        api_url = "https://member.moc.gov.tw/MOCMC/T0002/getMemberData"


        # 定義請求參數
        params = {
            'SYS_ID': 'CRAFT_NTCRI',
            'SYS_PASSWORD': 'luZ2le0W',
            'AuthToken': '5a367872-faab-4e6a-bbbc-81691712ae6e',
            'IS_DEV': 'Y'
        }
        response = requests.get(api_url, params=params)
    except Exception as e:
        return {"msg": str(e), "code": 500}