package com.durian.tssparty.presentation.screens

import android.app.Activity
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.durian.tssparty.domain.model.SessionStatus
import com.journeyapps.barcodescanner.ScanContract
import com.journeyapps.barcodescanner.ScanOptions

/**
 * Session info returned from validateInviteCode API
 * Matches service-party-app SessionInfo type
 */
data class JoinSessionInfo(
    val sessionId: String,
    val walletName: String,
    val thresholdT: Int,
    val thresholdN: Int,
    val initiator: String,
    val currentParticipants: Int,
    val totalParticipants: Int
)

/**
 * Format countdown seconds to mm:ss display
 */
private fun formatCountdown(seconds: Long): String {
    if (seconds < 0) return ""
    val minutes = seconds / 60
    val secs = seconds % 60
    return "%d:%02d".format(minutes, secs)
}

/**
 * JoinKeygen screen matching service-party-app/src/renderer/src/pages/Join.tsx
 * Simplified flow without password: input → confirm → joining
 */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun JoinKeygenScreen(
    sessionStatus: SessionStatus,
    isLoading: Boolean,
    error: String?,
    sessionInfo: JoinSessionInfo? = null,
    participants: List<String> = emptyList(),
    currentRound: Int = 0,
    totalRounds: Int = 9,
    publicKey: String? = null,
    countdownSeconds: Long = -1L,  // 5-minute countdown: -1 = not counting, >0 = remaining seconds
    onValidateInviteCode: (inviteCode: String) -> Unit,
    onJoinKeygen: (inviteCode: String, password: String) -> Unit,
    onCancel: () -> Unit,
    onResetState: () -> Unit = {},  // Reset ViewModel state without navigating
    onBackToHome: () -> Unit = {}
) {
    var inviteCode by remember { mutableStateOf("") }
    var validationError by remember { mutableStateOf<String?>(null) }

    // 3-step flow: input → confirm → joining
    var step by remember { mutableStateOf("input") }
    var autoJoinAttempted by remember { mutableStateOf(false) }

    // Handle session info received (validation success)
    LaunchedEffect(sessionInfo) {
        if (sessionInfo != null && step == "input") {
            step = "confirm"
        }
    }

    // Auto-join when we have session info (password is empty string)
    LaunchedEffect(step, sessionInfo, autoJoinAttempted, isLoading) {
        if (step == "confirm" && sessionInfo != null && !autoJoinAttempted && !isLoading && error == null) {
            autoJoinAttempted = true
            step = "joining"
            onJoinKeygen(inviteCode, "") // Empty password
        }
    }

    // Handle session status changes
    LaunchedEffect(sessionStatus) {
        when (sessionStatus) {
            SessionStatus.IN_PROGRESS -> {
                step = "progress"
            }
            SessionStatus.COMPLETED -> {
                step = "completed"
            }
            SessionStatus.FAILED -> {
                if (step == "joining") {
                    step = "confirm"
                }
            }
            else -> {}
        }
    }

    // Reset auto-join on error
    LaunchedEffect(error) {
        if (error != null && step == "joining") {
            step = "confirm"
            autoJoinAttempted = false
        }
    }

    // Reset to input state (used by cancel buttons in confirm/joining/progress screens)
    // This resets UI state to input screen WITHOUT navigating away from JoinKeygen page
    val resetToInput: () -> Unit = {
        step = "input"
        inviteCode = ""
        validationError = null
        autoJoinAttempted = false
        onResetState() // Clear ViewModel state (sessionInfo, joinToken, etc.) without navigating
    }

    when (step) {
        "input" -> InputScreen(
            inviteCode = inviteCode,
            isLoading = isLoading,
            error = error,
            validationError = validationError,
            onInviteCodeChange = { inviteCode = it },
            onValidateCode = {
                when {
                    inviteCode.isBlank() -> validationError = "请输入邀请码"
                    else -> {
                        validationError = null
                        onValidateInviteCode(inviteCode)
                    }
                }
            },
            onCancel = onCancel  // In input state, cancel navigates away
        )
        "confirm" -> ConfirmScreen(
            sessionInfo = sessionInfo,
            isLoading = isLoading,
            error = error,
            onBack = {
                step = "input"
                autoJoinAttempted = false
            },
            onRetry = {
                autoJoinAttempted = false
            },
            onCancel = resetToInput  // Reset to input state, stay on page
        )
        "joining" -> JoiningScreen(
            countdownSeconds = countdownSeconds,
            onCancel = resetToInput
        )  // Reset to input state, stay on page
        "progress" -> KeygenProgressScreen(
            sessionStatus = sessionStatus,
            participants = participants,
            currentRound = currentRound,
            totalRounds = totalRounds,
            countdownSeconds = countdownSeconds,
            onCancel = resetToInput  // Reset to input state, stay on page
        )
        "completed" -> KeygenCompletedScreen(
            publicKey = publicKey,
            onBackToHome = onBackToHome
        )
    }
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun InputScreen(
    inviteCode: String,
    isLoading: Boolean,
    error: String?,
    validationError: String?,
    onInviteCodeChange: (String) -> Unit,
    onValidateCode: () -> Unit,
    onCancel: () -> Unit
) {
    val context = LocalContext.current

    // QR Scanner launcher
    val scanLauncher = rememberLauncherForActivityResult(
        contract = ScanContract()
    ) { result ->
        if (result.contents != null) {
            // Parse the scanned content (could be invite code or deep link)
            val scannedContent = result.contents
            val extractedCode = if (scannedContent.startsWith("tssparty://join/")) {
                scannedContent.removePrefix("tssparty://join/")
            } else {
                scannedContent
            }
            onInviteCodeChange(extractedCode)
        }
    }

    Column(
        modifier = Modifier
            .fillMaxSize()
            .verticalScroll(rememberScrollState())
            .padding(16.dp)
    ) {
        // Header
        Text(
            text = "加入共管钱包",
            style = MaterialTheme.typography.headlineMedium,
            fontWeight = FontWeight.Bold
        )

        Spacer(modifier = Modifier.height(8.dp))

        Text(
            text = "扫描二维码或输入邀请码加入多方钱包创建会话",
            style = MaterialTheme.typography.bodyMedium,
            color = MaterialTheme.colorScheme.onSurfaceVariant
        )

        Spacer(modifier = Modifier.height(24.dp))

        // Scan QR Button
        Card(
            onClick = {
                val options = ScanOptions().apply {
                    setDesiredBarcodeFormats(ScanOptions.QR_CODE)
                    setPrompt("扫描邀请二维码")
                    setCameraId(0)
                    setBeepEnabled(true)
                    setBarcodeImageEnabled(false)
                    setOrientationLocked(true)
                    setCaptureActivity(PortraitCaptureActivity::class.java)
                }
                scanLauncher.launch(options)
            },
            modifier = Modifier.fillMaxWidth(),
            colors = CardDefaults.cardColors(
                containerColor = MaterialTheme.colorScheme.primaryContainer
            )
        ) {
            Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(20.dp),
                horizontalArrangement = Arrangement.Center,
                verticalAlignment = Alignment.CenterVertically
            ) {
                Icon(
                    Icons.Default.QrCodeScanner,
                    contentDescription = null,
                    modifier = Modifier.size(32.dp),
                    tint = MaterialTheme.colorScheme.onPrimaryContainer
                )
                Spacer(modifier = Modifier.width(12.dp))
                Text(
                    text = "扫描二维码",
                    style = MaterialTheme.typography.titleMedium,
                    fontWeight = FontWeight.Medium,
                    color = MaterialTheme.colorScheme.onPrimaryContainer
                )
            }
        }

        Spacer(modifier = Modifier.height(24.dp))

        // Divider with "或"
        Row(
            modifier = Modifier.fillMaxWidth(),
            verticalAlignment = Alignment.CenterVertically
        ) {
            Divider(modifier = Modifier.weight(1f))
            Text(
                text = "  或  ",
                style = MaterialTheme.typography.bodyMedium,
                color = MaterialTheme.colorScheme.onSurfaceVariant
            )
            Divider(modifier = Modifier.weight(1f))
        }

        Spacer(modifier = Modifier.height(24.dp))

        // Invite Code Input
        OutlinedTextField(
            value = inviteCode,
            onValueChange = onInviteCodeChange,
            label = { Text("邀请码") },
            placeholder = { Text("粘贴邀请码") },
            leadingIcon = {
                Icon(Icons.Default.Key, contentDescription = null)
            },
            modifier = Modifier.fillMaxWidth(),
            singleLine = true,
            enabled = !isLoading
        )

        Spacer(modifier = Modifier.height(16.dp))

        // Info card
        Card(
            colors = CardDefaults.cardColors(
                containerColor = MaterialTheme.colorScheme.secondaryContainer
            ),
            modifier = Modifier.fillMaxWidth()
        ) {
            Row(
                modifier = Modifier.padding(12.dp),
                verticalAlignment = Alignment.Top
            ) {
                Icon(
                    Icons.Default.Info,
                    contentDescription = null,
                    tint = MaterialTheme.colorScheme.onSecondaryContainer,
                    modifier = Modifier.size(20.dp)
                )
                Spacer(modifier = Modifier.width(8.dp))
                Text(
                    text = "请向会话发起者获取邀请二维码或邀请码",
                    style = MaterialTheme.typography.bodySmall,
                    color = MaterialTheme.colorScheme.onSecondaryContainer
                )
            }
        }

        Spacer(modifier = Modifier.height(16.dp))

        // Error display
        error?.let {
            Card(
                colors = CardDefaults.cardColors(
                    containerColor = MaterialTheme.colorScheme.errorContainer
                ),
                modifier = Modifier.fillMaxWidth()
            ) {
                Row(
                    modifier = Modifier.padding(12.dp),
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Icon(
                        Icons.Default.Error,
                        contentDescription = null,
                        tint = MaterialTheme.colorScheme.error
                    )
                    Spacer(modifier = Modifier.width(8.dp))
                    Text(
                        text = it,
                        color = MaterialTheme.colorScheme.onErrorContainer
                    )
                }
            }
            Spacer(modifier = Modifier.height(16.dp))
        }

        validationError?.let {
            Card(
                colors = CardDefaults.cardColors(
                    containerColor = MaterialTheme.colorScheme.errorContainer
                ),
                modifier = Modifier.fillMaxWidth()
            ) {
                Row(
                    modifier = Modifier.padding(12.dp),
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Icon(
                        Icons.Default.Warning,
                        contentDescription = null,
                        tint = MaterialTheme.colorScheme.error
                    )
                    Spacer(modifier = Modifier.width(8.dp))
                    Text(
                        text = it,
                        color = MaterialTheme.colorScheme.onErrorContainer
                    )
                }
            }
            Spacer(modifier = Modifier.height(16.dp))
        }

        Spacer(modifier = Modifier.weight(1f))

        // Buttons
        Row(
            modifier = Modifier.fillMaxWidth(),
            horizontalArrangement = Arrangement.spacedBy(12.dp)
        ) {
            OutlinedButton(
                onClick = onCancel,
                modifier = Modifier.weight(1f),
                enabled = !isLoading
            ) {
                Text("取消")
            }

            Button(
                onClick = onValidateCode,
                modifier = Modifier.weight(1f),
                enabled = !isLoading && inviteCode.isNotBlank()
            ) {
                if (isLoading) {
                    CircularProgressIndicator(
                        modifier = Modifier.size(24.dp),
                        color = MaterialTheme.colorScheme.onPrimary,
                        strokeWidth = 2.dp
                    )
                    Spacer(modifier = Modifier.width(8.dp))
                    Text("验证中...")
                } else {
                    Text("加入会话")
                }
            }
        }
    }
}

@Composable
private fun ConfirmScreen(
    sessionInfo: JoinSessionInfo?,
    isLoading: Boolean,
    error: String?,
    onBack: () -> Unit,
    onRetry: () -> Unit,
    onCancel: () -> Unit
) {
    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(16.dp),
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        // Header
        Text(
            text = "确认会话信息",
            style = MaterialTheme.typography.headlineMedium,
            fontWeight = FontWeight.Bold
        )

        Spacer(modifier = Modifier.height(24.dp))

        // Session info card
        if (sessionInfo != null) {
            Card(
                modifier = Modifier.fillMaxWidth()
            ) {
                Column(modifier = Modifier.padding(16.dp)) {
                    InfoRow("钱包名称", sessionInfo.walletName)
                    Divider(modifier = Modifier.padding(vertical = 8.dp))
                    InfoRow("阈值设置", "${sessionInfo.thresholdT}-of-${sessionInfo.thresholdN}")
                    Divider(modifier = Modifier.padding(vertical = 8.dp))
                    InfoRow("发起者", sessionInfo.initiator)
                    Divider(modifier = Modifier.padding(vertical = 8.dp))
                    InfoRow("当前参与者", "${sessionInfo.currentParticipants} / ${sessionInfo.totalParticipants}")
                }
            }
        }

        Spacer(modifier = Modifier.height(24.dp))

        // Error or auto-joining state
        if (error != null) {
            Card(
                colors = CardDefaults.cardColors(
                    containerColor = MaterialTheme.colorScheme.errorContainer
                ),
                modifier = Modifier.fillMaxWidth()
            ) {
                Row(
                    modifier = Modifier.padding(12.dp),
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Icon(
                        Icons.Default.Error,
                        contentDescription = null,
                        tint = MaterialTheme.colorScheme.error
                    )
                    Spacer(modifier = Modifier.width(8.dp))
                    Text(
                        text = error,
                        color = MaterialTheme.colorScheme.onErrorContainer
                    )
                }
            }

            Spacer(modifier = Modifier.height(24.dp))

            Row(
                modifier = Modifier.fillMaxWidth(),
                horizontalArrangement = Arrangement.spacedBy(12.dp)
            ) {
                OutlinedButton(
                    onClick = onCancel,
                    modifier = Modifier.weight(1f)
                ) {
                    Text("取消")
                }
                Button(
                    onClick = onRetry,
                    modifier = Modifier.weight(1f)
                ) {
                    Text("重试")
                }
            }
        } else {
            // Auto-joining state
            CircularProgressIndicator(modifier = Modifier.size(48.dp))
            Spacer(modifier = Modifier.height(16.dp))
            Text(
                text = "正在自动加入会话...",
                style = MaterialTheme.typography.bodyLarge
            )

            Spacer(modifier = Modifier.height(24.dp))

            // Cancel button during auto-join
            OutlinedButton(onClick = onCancel) {
                Icon(Icons.Default.Cancel, contentDescription = null)
                Spacer(modifier = Modifier.width(8.dp))
                Text("取消")
            }
        }
    }
}

@Composable
private fun JoiningScreen(
    countdownSeconds: Long = -1L,
    onCancel: () -> Unit
) {
    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(16.dp),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center
    ) {
        CircularProgressIndicator(
            modifier = Modifier.size(80.dp),
            strokeWidth = 6.dp
        )

        Spacer(modifier = Modifier.height(32.dp))

        Text(
            text = "正在加入会话...",
            style = MaterialTheme.typography.headlineSmall,
            fontWeight = FontWeight.Bold
        )

        Spacer(modifier = Modifier.height(16.dp))

        Text(
            text = "请稍候，正在连接到其他参与者",
            style = MaterialTheme.typography.bodyMedium,
            color = MaterialTheme.colorScheme.onSurfaceVariant
        )

        // Countdown timer (if counting down)
        if (countdownSeconds > 0) {
            Spacer(modifier = Modifier.height(24.dp))
            Card(
                colors = CardDefaults.cardColors(
                    containerColor = MaterialTheme.colorScheme.tertiaryContainer
                )
            ) {
                Row(
                    modifier = Modifier.padding(horizontal = 24.dp, vertical = 12.dp),
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Icon(
                        Icons.Default.Timer,
                        contentDescription = null,
                        tint = MaterialTheme.colorScheme.onTertiaryContainer,
                        modifier = Modifier.size(20.dp)
                    )
                    Spacer(modifier = Modifier.width(8.dp))
                    Text(
                        text = "等待启动: ${formatCountdown(countdownSeconds)}",
                        style = MaterialTheme.typography.titleMedium,
                        fontWeight = FontWeight.Bold,
                        color = MaterialTheme.colorScheme.onTertiaryContainer
                    )
                }
            }
        }

        Spacer(modifier = Modifier.height(32.dp))

        // Cancel button
        OutlinedButton(onClick = onCancel) {
            Icon(Icons.Default.Cancel, contentDescription = null)
            Spacer(modifier = Modifier.width(8.dp))
            Text("取消")
        }
    }
}

@Composable
private fun KeygenProgressScreen(
    sessionStatus: SessionStatus,
    participants: List<String>,
    currentRound: Int,
    totalRounds: Int,
    countdownSeconds: Long = -1L,
    onCancel: () -> Unit
) {
    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(16.dp),
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        // Header
        Text(
            text = "密钥生成中",
            style = MaterialTheme.typography.headlineMedium,
            fontWeight = FontWeight.Bold
        )

        Spacer(modifier = Modifier.height(8.dp))

        Text(
            text = "请保持应用在前台，直到密钥生成完成",
            style = MaterialTheme.typography.bodyMedium,
            color = MaterialTheme.colorScheme.onSurfaceVariant
        )

        Spacer(modifier = Modifier.height(32.dp))

        // Progress indicator
        CircularProgressIndicator(
            modifier = Modifier.size(80.dp),
            strokeWidth = 6.dp
        )

        Spacer(modifier = Modifier.height(24.dp))

        // Progress card
        Card(modifier = Modifier.fillMaxWidth()) {
            Column(modifier = Modifier.padding(16.dp)) {
                Row(
                    modifier = Modifier.fillMaxWidth(),
                    horizontalArrangement = Arrangement.SpaceBetween
                ) {
                    Text(
                        text = "协议进度",
                        style = MaterialTheme.typography.titleSmall,
                        fontWeight = FontWeight.Medium
                    )
                    Text(
                        text = "$currentRound / $totalRounds",
                        style = MaterialTheme.typography.bodySmall,
                        color = MaterialTheme.colorScheme.onSurfaceVariant
                    )
                }
                Spacer(modifier = Modifier.height(8.dp))
                LinearProgressIndicator(
                    progress = if (totalRounds > 0) currentRound.toFloat() / totalRounds else 0f,
                    modifier = Modifier.fillMaxWidth()
                )
            }
        }

        // Countdown timer (if counting down - waiting for keygen to start)
        if (countdownSeconds > 0) {
            Spacer(modifier = Modifier.height(16.dp))
            Card(
                modifier = Modifier.fillMaxWidth(),
                colors = CardDefaults.cardColors(
                    containerColor = MaterialTheme.colorScheme.tertiaryContainer
                )
            ) {
                Row(
                    modifier = Modifier
                        .fillMaxWidth()
                        .padding(16.dp),
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Icon(
                        Icons.Default.Timer,
                        contentDescription = null,
                        tint = MaterialTheme.colorScheme.onTertiaryContainer,
                        modifier = Modifier.size(24.dp)
                    )
                    Spacer(modifier = Modifier.width(12.dp))
                    Column {
                        Text(
                            text = "等待密钥生成启动",
                            style = MaterialTheme.typography.labelMedium,
                            color = MaterialTheme.colorScheme.onTertiaryContainer
                        )
                        Text(
                            text = formatCountdown(countdownSeconds),
                            style = MaterialTheme.typography.headlineMedium,
                            fontWeight = FontWeight.Bold,
                            color = MaterialTheme.colorScheme.onTertiaryContainer
                        )
                    }
                }
            }
        }

        Spacer(modifier = Modifier.height(16.dp))

        // Participants card
        if (participants.isNotEmpty()) {
            Card(modifier = Modifier.fillMaxWidth()) {
                Column(modifier = Modifier.padding(16.dp)) {
                    Text(
                        text = "参与方 (${participants.size})",
                        style = MaterialTheme.typography.titleSmall,
                        fontWeight = FontWeight.Medium
                    )
                    Spacer(modifier = Modifier.height(8.dp))
                    participants.forEach { participant ->
                        Row(
                            modifier = Modifier
                                .fillMaxWidth()
                                .padding(vertical = 4.dp),
                            verticalAlignment = Alignment.CenterVertically
                        ) {
                            Icon(
                                Icons.Default.Person,
                                contentDescription = null,
                                modifier = Modifier.size(20.dp),
                                tint = MaterialTheme.colorScheme.primary
                            )
                            Spacer(modifier = Modifier.width(8.dp))
                            Text(
                                text = participant,
                                style = MaterialTheme.typography.bodyMedium
                            )
                        }
                    }
                }
            }
        }

        Spacer(modifier = Modifier.weight(1f))

        // Cancel button
        OutlinedButton(onClick = onCancel) {
            Icon(Icons.Default.Cancel, contentDescription = null)
            Spacer(modifier = Modifier.width(8.dp))
            Text("取消")
        }
    }
}

@Composable
private fun KeygenCompletedScreen(
    publicKey: String?,
    onBackToHome: () -> Unit
) {
    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(16.dp),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center
    ) {
        // Success icon
        Icon(
            Icons.Default.CheckCircle,
            contentDescription = null,
            modifier = Modifier.size(80.dp),
            tint = MaterialTheme.colorScheme.primary
        )

        Spacer(modifier = Modifier.height(24.dp))

        Text(
            text = "密钥生成成功！",
            style = MaterialTheme.typography.headlineMedium,
            fontWeight = FontWeight.Bold
        )

        Spacer(modifier = Modifier.height(16.dp))

        Text(
            text = "您的钱包已创建成功，可以在「我的钱包」中查看",
            style = MaterialTheme.typography.bodyMedium,
            color = MaterialTheme.colorScheme.onSurfaceVariant
        )

        Spacer(modifier = Modifier.height(32.dp))

        // Public key info
        if (publicKey != null) {
            Card(
                modifier = Modifier.fillMaxWidth(),
                colors = CardDefaults.cardColors(
                    containerColor = MaterialTheme.colorScheme.surfaceVariant
                )
            ) {
                Column(modifier = Modifier.padding(16.dp)) {
                    Text(
                        text = "公钥",
                        style = MaterialTheme.typography.labelSmall,
                        color = MaterialTheme.colorScheme.onSurfaceVariant
                    )
                    Spacer(modifier = Modifier.height(4.dp))
                    Text(
                        text = "${publicKey.take(20)}...${publicKey.takeLast(20)}",
                        style = MaterialTheme.typography.bodySmall,
                        fontWeight = FontWeight.Medium
                    )
                }
            }
        }

        Spacer(modifier = Modifier.height(32.dp))

        Button(
            onClick = onBackToHome,
            modifier = Modifier.fillMaxWidth()
        ) {
            Icon(Icons.Default.Home, contentDescription = null)
            Spacer(modifier = Modifier.width(8.dp))
            Text("返回首页")
        }
    }
}

@Composable
private fun InfoRow(label: String, value: String) {
    Row(
        modifier = Modifier.fillMaxWidth(),
        horizontalArrangement = Arrangement.SpaceBetween
    ) {
        Text(
            text = label,
            style = MaterialTheme.typography.bodyMedium,
            color = MaterialTheme.colorScheme.onSurfaceVariant
        )
        Text(
            text = value,
            style = MaterialTheme.typography.bodyMedium,
            fontWeight = FontWeight.Medium
        )
    }
}
