package com.example.demo.notice;

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

@Converter(autoApply = false)
public class NoticeStatusConverter implements AttributeConverter<NoticeStatus, String> {
    @Override
    public String convertToDatabaseColumn(NoticeStatus attribute) {
        if (attribute == null) return null;
        switch (attribute) {
            case DRAFT:
                return "draft";
            case PUBLISHED:
                return "published";
            case OFFLINE:
                return "offline";
            default:
                return "published";
        }
    }

    @Override
    public NoticeStatus convertToEntityAttribute(String dbData) {
        if (dbData == null) return null;
        switch (dbData) {
            case "draft":
                return NoticeStatus.DRAFT;
            case "published":
                return NoticeStatus.PUBLISHED;
            case "offline":
                return NoticeStatus.OFFLINE;
            default:
                return NoticeStatus.PUBLISHED;
        }
    }
}


