#!/usr/bin/env python3

import importlib.util
import os

from fenrirscreenreader.core.i18n import _

# Load base configuration class
_base_path = os.path.join(os.path.dirname(__file__), "..", "config_base.py")
_spec = importlib.util.spec_from_file_location("config_base", _base_path)
_module = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(_module)
config_command = _module.config_command


class command(config_command):
    def __init__(self):
        super().__init__()

    def get_description(self):
        return "Set screen encoding to UTF-8 (Unicode)"

    def run(self):
        current_encoding = self.get_setting("screen", "encoding", "auto")
        
        if current_encoding.lower() == "utf-8":
            self.present_text("Screen encoding already set to UTF-8")
            return
        
        success = self.set_setting("screen", "encoding", "utf-8")
        
        if success:
            self.present_text("Screen encoding set to UTF-8 - Unicode text encoding")
            self.play_sound("Accept")
        else:
            self.present_text("Failed to change screen encoding")
            self.play_sound("Error")