# -*- coding: utf-8 -*-
"""
@File: config.py
@Date: 2020-09-14
@author: A2TEC
@section MODIFYINFO 수정정보
- 수정자/수정일   : 수정내역
- 2022-01-14/hsj100@a2tec.co.kr : refactoring
@brief: Configurations
"""

from dataclasses import dataclass
from os import path, environ

from main_rest.app.common import consts
from main_rest.app.models import UserInfo

base_dir = path.dirname(path.dirname(path.dirname(path.abspath(__file__))))


@dataclass
class Config:
    """
    기본 Configuration
    """
    BASE_DIR: str = base_dir
    DB_POOL_RECYCLE: int = 900
    DB_ECHO: bool = True
    DEBUG: bool = False
    TEST_MODE: bool = False
    DEV_TEST_CONNECT_ACCOUNT: str | None = None

    # NOTE(hsj100): SERVICE_AUTH_API_KEY (token 방식으로 진행)
    SERVICE_AUTH_API_KEY: bool = False

    DB_URL: str = environ.get('DB_URL', f'mysql+pymysql://{consts.DB_USER_ID}:{consts.DB_USER_PW}@{consts.DB_ADDRESS}:{consts.DB_PORT}/{consts.DB_NAME}?charset={consts.DB_CHARSET}')
    REST_SERVER_PORT = consts.REST_SERVER_PORT

    SW_TITLE = consts.SW_TITLE
    SW_VERSION = consts.SW_VERSION
    SW_DESCRIPTION = consts.SW_DESCRIPTION
    TERMS_OF_SERVICE = consts.TERMS_OF_SERVICE
    CONTEACT = consts.CONTEACT
    LICENSE_INFO = consts.LICENSE_INFO

    GLOBAL_TOKEN = consts.ADMIN_INIT_ACCOUNT_INFO.connect_token
    
    COOKIES_AUTH = 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MTQsImVtYWlsIjoia29hbGFAZGluZ3JyLmNvbSIsIm5hbWUiOm51bGwsInBob25lX251bWJlciI6bnVsbCwicHJvZmlsZV9pbWciOm51bGwsInNuc190eXBlIjpudWxsfQ.4vgrFvxgH8odoXMvV70BBqyqXOFa2NDQtzYkGywhV48'


@dataclass
class ReleaseConfig(Config):
    TRUSTED_HOSTS = ['*']
    ALLOW_SITE = ['*']
    DEBUG: bool = True

@dataclass
class ProdConfig(Config):
    TRUSTED_HOSTS = ['*']
    ALLOW_SITE = ['*']


@dataclass
class TestConfig(Config):
    DB_URL: str = environ.get('DB_URL', f'mysql+pymysql://{consts.DB_USER_ID}:{consts.DB_USER_PW}@{consts.DB_ADDRESS}/{consts.DB_NAME}_test?charset={consts.DB_CHARSET}')
    TRUSTED_HOSTS = ['*']
    ALLOW_SITE = ['*']
    TEST_MODE: bool = True


@dataclass
class DevConfig(Config):
    TRUSTED_HOSTS = ['*']
    ALLOW_SITE = ['*']
    DEBUG: bool = True

    SW_TITLE = '[Dev] ' + consts.SW_TITLE


@dataclass
class MyConfig(Config):
    TRUSTED_HOSTS = ['*']
    ALLOW_SITE = ['*']
    DEBUG: bool = True
    DB_URL: str = environ.get('DB_URL', f'mysql+pymysql://{consts.DB_USER_ID}:{consts.DB_USER_PW}@{consts.DB_ADDRESS}/{consts.DB_NAME}_my?charset={consts.DB_CHARSET}')
    REST_SERVER_PORT = consts.REST_SERVER_PORT + 2

    # NOTE(hsj100): DEV_TEST_CONNECT_ACCOUNT
    # DEV_TEST_CONNECT_ACCOUNT: UserInfo = UserInfo(**consts.ADMIN_INIT_ACCOUNT_INFO)
    # DEV_TEST_CONNECT_ACCOUNT: str = None

    # NOTE(hsj100): SERVICE_AUTH_API_KEY (token 방식으로 진행)
    SERVICE_AUTH_API_KEY: bool = False

    SW_TITLE = '[My] ' + consts.SW_TITLE


def conf():
    """
    환경 불러오기
    :return:
    """
    from config import rest_config
    
    config = dict(prod=ProdConfig, release=ReleaseConfig, test=TestConfig, dev=DevConfig, my=MyConfig)
    return config[environ.get('API_ENV', rest_config.config)]()
    # return config[environ.get('API_ENV', 'dev')]()
    # return config[environ.get('API_ENV', 'my')]()
    # return config[environ.get('API_ENV', 'test')]()

