# Copyright (C) 2023 Pyresample developers
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program.  If not, see <http://www.gnu.org/licenses/>.
"""Central configuration management for pyresample."""

import os
import sys

import platformdirs
from donfig import Config

BASE_PATH = os.path.dirname(os.path.realpath(__file__))
PACKAGE_CONFIG_PATH = os.path.join(BASE_PATH, 'etc')

_user_config_dir = platformdirs.user_config_dir("pyresample", "pytroll")
_CONFIG_PATHS = [
    os.path.join(PACKAGE_CONFIG_PATH, 'pyresample.yaml'),
    os.getenv('PYRESAMPLE_ROOT_CONFIG', os.path.join('/etc', 'pyresample', 'pyresample.yaml')),
    os.path.join(sys.prefix, 'etc', 'pyresample', 'pyresample.yaml'),
    os.path.join(_user_config_dir, 'pyresample.yaml'),
    os.path.join(os.path.expanduser('~'), '.pyresample', 'pyresample.yaml'),
]

config = Config(
    "pyresample",
    defaults=[{
        "cache_dir": platformdirs.user_cache_dir("pyresample", "pytroll"),
        "cache_geometry_slices": False,
        "features": {
            "future_geometries": False,
        },
    }],
    paths=_CONFIG_PATHS,
)
