from dataclasses import dataclass
from pathlib import Path
import json


@dataclass
class BaseUnits:
    distance: float
    charge: float
    voltage: float
    concentrationM: float

    @property
    def charge_density(self):
        return self.charge / (self.distance ** 2)

    @property
    def energy(self):
        return self.charge * self.voltage

    @property
    def concentration(self):
        return self.concentrationM * 6.02214076 * 1e23 / (10 * self.distance) ** 3


@dataclass
class Constants:
    Boltzmann: float
    epsilon0: float
    e0: float


with open(Path(__file__).resolve().parent.joinpath('units.json')) as f:
    base_units = json.load(f)


UNITS = BaseUnits(**base_units)

# values of different constants in provided base units
CONSTANTS = Constants(Boltzmann=1.380649 * 1e-23 / UNITS.energy,
                      epsilon0=8.8541878128 * 1e-12 * UNITS.distance * UNITS.voltage / UNITS.charge,
                      e0=1.602176634 * 1e-19 / UNITS.charge)