package com.ffii.fpsms.modules.master.web.models

import java.math.BigDecimal
import java.time.LocalDateTime

data class DeleteItemUomRequest(
    val id: Long? = null,
    val m18Id: Long? = null
)

data class ItemUomRequest(
    val id: Long? = null,
    val uomId: Long? = null,
    val m18UomId: Long? = null,
    val itemId: Long? = null,
    val m18ItemId: Long? = null,
    val baseUnit: Boolean?,
    val stockUnit: Boolean?,
    val pickingUnit: Boolean?,
    val salesUnit: Boolean?,
    val purchaseUnit: Boolean?,
    val price: BigDecimal?,
    val currencyId: Long? = null,
    val m18CurrencyId: Long? = null,
    val m18Id: Long?,
    val m18LastModifyDate: LocalDateTime?,
    val ratioD: BigDecimal?,
    val ratioN: BigDecimal?,
    val itemRatioD: BigDecimal?,
    val itemRatioN: BigDecimal?,
    val deleted: Boolean?,
)
data class BomFormatIssue(
    val fileName: String,   // 檔名
    val problem: String     // 問題描述（用來 group 的 key）
)

// 回傳給前端用：問題 → 檔名列表
data class BomFormatProblemGroup(
    val problem: String,
    val fileNames: List<String>
)
data class BomFormatFileGroup(
    val fileName: String,
    val problems: List<String>
)

data class BomUploadResponse(
    val batchId: String,
    val fileNames: List<String>
)

data class BomFormatCheckRequest(
    val batchId: String
)

/** Format-check 回傳：正確檔名列表 + 失敗列表（檔名 + 問題） */
data class BomFormatCheckResponse(
    val correctFileNames: List<String>,
    val failList: List<BomFormatFileGroup>,
    val issueLogFileId: String? = null   // 或直接是 URL
)

data class ImportBomItemRequest(
    val fileName: String,
    val isAlsoWip: Boolean = false,
    val isDrink: Boolean = false
)

data class ImportBomRequestPayload(
    val batchId: String,
    val items: List<ImportBomItemRequest>
)

data class BomMaterialDto(
    val itemCode: String?,
    val itemName: String?,
    val isConsumable: Boolean?,
    val baseQty: BigDecimal?,
    val baseUom: String?,
    val stockQty: BigDecimal?,
    val stockUom: String?,
    val salesQty: BigDecimal?,
    val salesUom: String?
    
)

data class BomProcessDto(
    val seqNo: Long?,
    val processCode: String?,
    val processName: String?,
    val processDescription: String?,
    // For display we prefer equipment.code (stable identifier). Keep equipmentName for backward compatibility.
    val equipmentCode: String? = null,
    val equipmentName: String? = null,
    val durationInMinute: Int?,
    val prepTimeInMinute: Int?,
    val postProdTimeInMinute: Int?
)
data class BomExcelCheckProgress(
    val batchId: String,
    @Volatile var totalFiles: Int,
    @Volatile var processedFiles: Int,
    @Volatile var currentFileName: String?,  // 正在處理哪一個
    @Volatile var lastUpdateTime: Long       // 最後一次更新時間
)
data class BomDetailResponse(
    val id: Long,
    val itemCode: String?,
    val itemName: String?,
    val isDark: Boolean?,
    val isFloat: Int?,
    val isDense: Int?,
    val isDrink: Boolean?,
    val scrapRate: Int?,
    val allergicSubstances: Int?,
    val timeSequence: Int?,
    val complexity: Int?,
    val baseScore: Int?,
    val description: String?,
    val outputQty: BigDecimal?,
    val outputQtyUom: String?,
    val materials: List<BomMaterialDto>,
    val processes: List<BomProcessDto>
)