from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel
from odoo import http
from odoo.addons.fastapi.dependencies import odoo_env

router = APIRouter(tags=["kyc"])


class KYCOrderRequest(BaseModel):
    team_id: str
    team_name: str
    owner_id: str
    logto_org_id: str = ""


@router.post("/order")
def create_kyc_request(
    kyc_data: KYCOrderRequest,
    env=Depends(odoo_env)
):
    """Creates KYC request from team creation workflow"""
    
    KYCRequest = env['kyc.request']
    
    # Create KYC request
    kyc_vals = {
        'team_uuid': kyc_data.team_id,
        'team_name': kyc_data.team_name,
        'owner_id': kyc_data.owner_id,
        'logto_org_id': kyc_data.logto_org_id,
        'status': 'pending',
        'score': 0
    }
    
    kyc_request = KYCRequest.create(kyc_vals)
    env.cr.commit()
    
    return {
        "success": True,
        "kyc_id": kyc_request.id,
        "kyc_reference": kyc_request.name,
        "team_id": kyc_data.team_id,
        "team_name": kyc_data.team_name,
        "status": "pending",
        "message": "KYC request created successfully"
    }