"""115网盘适配器 v1.0.0"""

from ..base import BaseCloudDriveAdapter, FileInfo, TransferResult, VerifyResult
from ...errors import TransferError, TransferErrorCode
from .credential import Pan115CredentialManager
from .transfer import Pan115Transfer, parse_share_url
from .cleanup import Pan115Cleanup


class Pan115Adapter(BaseCloudDriveAdapter):
    PLATFORM_NAME = "115网盘"
    PLATFORM_KEY = "pan115"
    URL_PATTERNS = [r"115\.com/s/([a-z0-9]+)"]

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

    @property
    def _transfer(self):
        if self._transfer_engine is None:
            self._transfer_engine = Pan115Transfer(
                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)
