import logging
import sys

import pydantic
import yaml

from . import models

logger = logging.getLogger(__name__)

try:
    config = yaml.safe_load(open("config.yaml"))
except FileNotFoundError:
    logger.error(
        "No config.yaml file found. Make sure to copy the "
        "config.example.yaml file to config.yaml"
    )
    sys.exit(1)

try:
    config = models.Config(**config)
except pydantic.ValidationError as e:
    logger.error(f"Invalid config.yaml file: {e}")
    sys.exit(1)
