import os
from typing import Literal

from mmar_envops.aka_pydantic_settings import AkaBaseSettings, AkaField


class ExecConfig(AkaBaseSettings):
    debug: bool = AkaField(default=False, alias="d")
    time: bool = AkaField(default=False, alias="t")
    autoyes: bool = AkaField(default=False)
    dry: bool = False
    color: bool = True
    ripgrep_max_columns: int = 500
    prefer_env_keys: Literal["upper", "lower", "no"] = "no"

    def fix_key_case(self, key: str):
        pref = self.prefer_env_keys
        match pref:
            case "upper":
                return key.upper()
            case "lower":
                return key.lower()
            case _:
                return key


def is_debug():
    env = os.environ
    return (env.get("debug") or env.get("d")) in {"1", "true", "yes"} or False


def is_force():
    env = os.environ
    return env.get("force") in {"1", "true", "yes"} or False


def is_autoyes():
    env = os.environ
    return (env.get("autoyes")) in {"1", "true", "yes"} or False
