from ...Machine.PaedMLMachineCollection import MACHINE_COLLECTION
from ...Logging.Logger import log, Severity
from ..Playbooks.Playbook import FileCleanupTask, PlaybookCredentialCollection
from ...SetupSteps.SetupStep import SetupStep


class TriggerPcPatchPasswordChange(SetupStep):
    def __init__(self):
        super().__init__()

    def run(self, file_cleanup_stack: list[FileCleanupTask], credentials: PlaybookCredentialCollection) -> bool:
        log('Triggering PC patch password change...')
        stdout, stderr, retval = MACHINE_COLLECTION.backup.execute_shell_command('/usr/share/paedmllinux/pcpatch-password-change')

        if retval != 0:
            log(f'Could not trigger pcpatch password change: {stderr if len(stderr) > 0 else stdout}')
            return False

        log('Successfully triggered pcpatch password change.', Severity.DEBUG)
        return True