"""123云盘适配器 v1.0.0"""

from ..base import BaseCloudDriveAdapter, FileInfo, TransferResult, VerifyResult
from ...errors import TransferError, TransferErrorCode
from .credential import Pan123CredentialManager
from .transfer import Pan123Transfer
from .cleanup import Pan123Cleanup


class Pan123Adapter(BaseCloudDriveAdapter):
    PLATFORM_NAME = "123云盘"
    PLATFORM_KEY = "pan123"
    URL_PATTERNS = [r"123pan\.com/s/([A-Za-z0-9]+)"]

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._cred = Pan123CredentialManager(self.config)
        self._transfer_engine = None
        self._cln = Pan123Cleanup()

    @property
    def _transfer(self):
        if self._transfer_engine is None:
            self._transfer_engine = Pan123Transfer(
                self.session, self._cred, self.config, self.transfer_config)
        return self._transfer_engine

    def _get_share_detail(self, pwd_id, passcode=""):
        return self._transfer.get_share_info(pwd_id, passcode)

    def _save_files(self, pwd_id, detail, save_dir):
        return self._transfer.save_files(pwd_id, detail, save_dir)

    def _create_share(self, file_ids, title, password=""):
        return self._transfer.create_share(file_ids, title, password)

    def get_files(self, parent_fid="0"):
        return self._transfer.list_files(parent_fid)

    def delete(self, file_ids):
        return self._cln.delete_files(self.session, self._cred, file_ids)
