from __future__ import annotations

import dataclasses
import tomllib
import typing

@dataclasses.dataclass(eq=False, frozen=True, slots=True)
class Config:
	username: str
	fio_api_key: str
	punoted_api_key: str
	market: MarketConfig
	supply: dict[str, SupplyConfig]

	def __init__(self) -> None:
		with open('config.toml', 'rb') as f:
			config = tomllib.load(f)
		for k, v in config.items():
			match k:
				case 'market':
					v = MarketConfig(**v)
				case 'supply':
					v = {planet_name: SupplyConfig(**planet_config) for planet_name, planet_config in v.items()}
			object.__setattr__(self, k, v)

	def supply_config(self, planet_name: str) -> SupplyConfig:
		if (planet_config := self.supply.get(planet_name.lower())) is not None:
			return planet_config
		else:
			return SupplyConfig()

@dataclasses.dataclass(eq=False, frozen=True, slots=True)
class MarketConfig:
	mm_items: typing.Mapping[str, int]

@dataclasses.dataclass(eq=False, frozen=True, slots=True)
class SupplyConfig:
	ignore_materials: typing.Sequence[str] = dataclasses.field(default_factory=list)

config = Config()
