package backup

import (
	"github.com/uozi-tech/cosy"
)

var (
	e = cosy.NewErrorScope("backup")

	ErrCreateTempDir     = e.New(4002, "Failed to create temporary directory")
	ErrCreateTempSubDir  = e.New(4003, "Failed to create temporary subdirectory")
	ErrBackupNginxUI     = e.New(4004, "Failed to backup Nginx UI files: {0}")
	ErrBackupNginx       = e.New(4005, "Failed to backup Nginx config files: {0}")
	ErrCreateHashFile    = e.New(4006, "Failed to create hash info file: {0}")
	ErrEncryptNginxUIDir = e.New(4007, "Failed to encrypt Nginx UI directory: {0}")
	ErrEncryptNginxDir   = e.New(4008, "Failed to encrypt Nginx directory: {0}")
	ErrCreateZipArchive  = e.New(4009, "Failed to create zip archive: {0}")
	ErrGenerateAESKey    = e.New(4011, "Failed to generate AES key: {0}")
	ErrGenerateIV        = e.New(4012, "Failed to generate initialization vector: {0}")
	ErrCreateBackupFile  = e.New(4013, "Failed to create backup file: {0}")
	ErrCleanupTempDir    = e.New(4014, "Failed to cleanup temporary directory: {0}")
	ErrCreateManifest    = e.New(4015, "Failed to create backup manifest: {0}")
	ErrCreateManifestSig = e.New(4016, "Failed to create backup manifest signature: {0}")

	ErrConfigPathEmpty     = e.New(4101, "Config path is empty")
	ErrCopyConfigFile      = e.New(4102, "Failed to copy config file: {0}")
	ErrCopyDBFile          = e.New(4104, "Failed to copy database file: {0}")
	ErrCalculateHash       = e.New(4105, "Failed to calculate hash: {0}")
	ErrNginxConfigDirEmpty = e.New(4106, "Nginx config directory is not set")
	ErrCopyNginxConfigDir  = e.New(4107, "Failed to copy Nginx config directory: {0}")
	ErrReadSymlink         = e.New(4108, "Failed to read symlink: {0}")

	ErrReadFile           = e.New(4201, "Failed to read file: {0}")
	ErrEncryptFile        = e.New(4202, "Failed to encrypt file: {0}")
	ErrWriteEncryptedFile = e.New(4203, "Failed to write encrypted file: {0}")
	ErrEncryptData        = e.New(4204, "Failed to encrypt data: {0}")
	ErrDecryptData        = e.New(4205, "Failed to decrypt data: {0}")
	ErrInvalidPadding     = e.New(4206, "Invalid padding in decrypted data")

	ErrCreateZipFile   = e.New(4301, "Failed to create zip file: {0}")
	ErrCreateZipEntry  = e.New(4302, "Failed to create zip entry: {0}")
	ErrOpenSourceFile  = e.New(4303, "Failed to open source file: {0}")
	ErrCreateZipHeader = e.New(4304, "Failed to create zip header: {0}")
	ErrCopyContent     = e.New(4305, "Failed to copy file content: {0}")

	ErrCreateRestoreDir     = e.New(4501, "Failed to create restore directory: {0}")
	ErrExtractArchive       = e.New(4505, "Failed to extract archive: {0}")
	ErrDecryptNginxUIDir    = e.New(4506, "Failed to decrypt Nginx UI directory: {0}")
	ErrDecryptNginxDir      = e.New(4507, "Failed to decrypt Nginx directory: {0}")
	ErrVerifyHashes         = e.New(4508, "Failed to verify hashes: {0}")
	ErrRestoreNginxConfigs  = e.New(4509, "Failed to restore Nginx configs: {0}")
	ErrBackupFileNotFound   = e.New(4511, "Backup file not found: {0}")
	ErrInvalidSecurityToken = e.New(4512, "Invalid security token format")
	ErrInvalidAESKey        = e.New(4513, "Invalid AES key format: {0}")
	ErrInvalidAESIV         = e.New(4514, "Invalid AES IV format: {0}")

	ErrOpenZipFile     = e.New(4601, "Failed to open zip file: {0}")
	ErrCreateDir       = e.New(4602, "Failed to create directory: {0}")
	ErrCreateParentDir = e.New(4603, "Failed to create parent directory: {0}")
	ErrCreateFile      = e.New(4604, "Failed to create file: {0}")
	ErrOpenZipEntry    = e.New(4605, "Failed to open zip entry: {0}")
	ErrCreateSymlink   = e.New(4606, "Failed to create symbolic link: {0}")
	ErrInvalidFilePath = e.New(4607, "Invalid file path: {0}")

	ErrReadEncryptedFile  = e.New(4701, "Failed to read encrypted file: {0}")
	ErrDecryptFile        = e.New(4702, "Failed to decrypt file: {0}")
	ErrWriteDecryptedFile = e.New(4703, "Failed to write decrypted file: {0}")

	ErrReadHashFile       = e.New(4801, "Failed to read hash info file: {0}")
	ErrCalculateUIHash    = e.New(4802, "Failed to calculate Nginx UI hash: {0}")
	ErrCalculateNginxHash = e.New(4803, "Failed to calculate Nginx hash: {0}")
	ErrReadManifest       = e.New(4804, "Failed to read backup manifest: {0}")
	ErrReadManifestSig    = e.New(4805, "Failed to read backup manifest signature: {0}")
	ErrInvalidManifest    = e.New(4806, "Invalid backup manifest: {0}")
	ErrInvalidManifestSig = e.New(4807, "Invalid backup manifest signature")
	ErrBackupIntegrity    = e.New(4808, "Backup integrity verification failed")
	ErrUnsupportedFormat  = e.New(4809, "This backup uses an unsupported legacy format. Please create a new backup with a newer version before restoring.")
	ErrMissingManifest    = e.New(4810, "Backup manifest is missing required file entry: {0}")
	ErrSigningKeyMissing  = e.New(4811, "Backup signing key is unavailable")

	ErrAutoBackupPathRequired       = e.New(4903, "Backup path is required for custom directory backup")
	ErrAutoBackupS3ConfigIncomplete = e.New(4904, "S3 configuration is incomplete: missing {0}")
	ErrAutoBackupUnsupportedType    = e.New(4905, "Unsupported backup type: {0}")
	ErrAutoBackupWriteFile          = e.New(4907, "Failed to write backup file: {0}")
	ErrAutoBackupWriteKeyFile       = e.New(4908, "Failed to write security key file: {0}")
	ErrAutoBackupS3Upload           = e.New(4909, "S3 upload failed: {0}")

	ErrInvalidPath            = e.New(4910, "Invalid path: {0}")
	ErrPathNotInGrantedAccess = e.New(4911, "Path not in granted access paths: {0}")
	ErrBackupPathNotExist     = e.New(4912, "Backup path does not exist: {0}")
	ErrBackupPathAccess       = e.New(4913, "Cannot access backup path {0}: {1}")
	ErrBackupPathNotDirectory = e.New(4914, "Backup path is not a directory: {0}")
	ErrCreateStorageDir       = e.New(4915, "Failed to create storage directory {0}: {1}")
	ErrStoragePathAccess      = e.New(4916, "Cannot access storage path {0}: {1}")
)
