from typing import List, Optional, Tuple, Union

import re
import numpy as np
import pandas as pd
from pydantic import BaseModel, ValidationError

from classification_model.config.core import config
from classification_model.processing.data_manager import pre_processing




def validate_inputs(*, input_data: pd.DataFrame) -> Tuple[pd.DataFrame, Optional[dict]]:
    """Check model inputs for unprocessable values."""
    #pre_processed = pre_processing(dataframe=input_data)
    validated_data = input_data[config.model_config.features].copy()
    errors = None

    try:
        # replace numpy nans so that pydantic can validate
        MultipleTitanicDataInputs(
            inputs=validated_data.replace({np.nan: None}).to_dict(orient="records")
        )
    except ValidationError as error:
        errors = error.json()

    return validated_data, errors


class TitanicDataInputSchema(BaseModel):
    pclass: Optional[int]
    name: Optional[str]
    sex: Optional[str]
    age: Optional[int]
    sibsp: Optional[int]
    parch: Optional[int] 
    ticket: Optional[int]
    fare : Optional[float]
    cabin: Optional[str]
    embarked: Optional[str]
    title: Optional[str]
    boat: Optional[Union[str, int]]
    body: Optional[int]
    #home.dest: 

class MultipleTitanicDataInputs(BaseModel):
    inputs: List[TitanicDataInputSchema]


