package com.ffii.fpsms.modules.purchaseOrder.enums

import jakarta.persistence.AttributeConverter
import jakarta.persistence.Converter

// Purchase Order Status
@Converter(autoApply = true)
class PurchaseOrderStatusConverter : AttributeConverter<PurchaseOrderStatus, String>{
    override fun convertToDatabaseColumn(status: PurchaseOrderStatus?): String? {
        return status?.value
    }

    override fun convertToEntityAttribute(value: String?): PurchaseOrderStatus? {
        return value?.let { v ->
            PurchaseOrderStatus.entries.find { it.value == v }
        }
    }
}

// Purchase Order Type
@Converter(autoApply = true)
class PurchaseOrderTypeConverter : AttributeConverter<PurchaseOrderType, String>{
    override fun convertToDatabaseColumn(status: PurchaseOrderType?): String? {
        return status?.value
    }

    override fun convertToEntityAttribute(value: String?): PurchaseOrderType? {
        return value?.let { v ->
            PurchaseOrderType.entries.find { it.value == v }
        }
    }
}