from __future__ import annotations

from uuid import uuid4

from epiuclid.serializers.pathway_mapper import (
    HalfLifeEntry,
    IUCLIDEndpointStudyRecordData,
    IUCLIDReferenceSubstanceData,
    IUCLIDSubstanceData,
    IUCLIDTransformationProductEntry,
    SoilPropertiesData,
)


def make_substance_data(**overrides) -> IUCLIDSubstanceData:
    payload = {
        "uuid": uuid4(),
        "name": "Atrazine",
        "reference_substance_uuid": uuid4(),
    }
    payload.update(overrides)
    return IUCLIDSubstanceData(**payload)


def make_reference_substance_data(**overrides) -> IUCLIDReferenceSubstanceData:
    payload = {
        "uuid": uuid4(),
        "name": "Atrazine",
        "smiles": "CCNc1nc(Cl)nc(NC(C)C)n1",
        "cas_number": "1912-24-9",
        "ec_number": "217-617-8",
        "iupac_name": "6-chloro-N2-ethyl-N4-isopropyl-1,3,5-triazine-2,4-diamine",
        "molecular_formula": "C8H14ClN5",
        "molecular_weight": 215.68,
        "inchi": (
            "InChI=1S/C8H14ClN5/c1-4-10-7-12-6(9)11-8(13-7)"
            "14-5(2)3/h5H,4H2,1-3H3,(H2,10,11,12,13,14)"
        ),
        "inchi_key": "MXWJVTOOROXGIU-UHFFFAOYSA-N",
    }
    payload.update(overrides)
    return IUCLIDReferenceSubstanceData(**payload)


def make_half_life_entry(**overrides) -> HalfLifeEntry:
    payload = {
        "model": "SFO",
        "dt50_start": 12.5,
        "dt50_end": 15.0,
        "unit": "d",
        "source": "Model prediction",
        "soil_no_code": None,
        "temperature": None,
    }
    payload.update(overrides)
    return HalfLifeEntry(**payload)


def make_transformation_entry(**overrides) -> IUCLIDTransformationProductEntry:
    payload = {
        "uuid": uuid4(),
        "product_reference_uuid": uuid4(),
        "parent_reference_uuids": [uuid4()],
        "kinetic_formation_fraction": 0.42,
    }
    payload.update(overrides)
    return IUCLIDTransformationProductEntry(**payload)


def make_soil_properties_data(**overrides) -> SoilPropertiesData:
    payload = {
        "soil_no_code": None,
        "clay": 20.0,
        "silt": 30.0,
        "sand": 50.0,
        "org_carbon": 1.5,
        "ph_lower": 6.0,
        "ph_upper": 7.0,
        "ph_method": "CaCl2",
        "cec": 12.0,
        "moisture_content": 40.0,
        "soil_type": "LOAM",
        "soil_classification": "USDA",
    }
    payload.update(overrides)
    return SoilPropertiesData(**payload)


def make_endpoint_study_record_data(**overrides) -> IUCLIDEndpointStudyRecordData:
    payload = {
        "uuid": uuid4(),
        "substance_uuid": uuid4(),
        "name": "Biodegradation study",
        "half_lives": [],
        "temperature": None,
        "transformation_products": [],
        "model_name_and_version": [],
        "software_name_and_version": [],
        "model_remarks": [],
    }
    payload.update(overrides)
    return IUCLIDEndpointStudyRecordData(**payload)
