package de.effigenix.infrastructure.masterdata.persistence.mapper;

import de.effigenix.domain.masterdata.CategoryName;
import de.effigenix.domain.masterdata.ProductCategory;
import de.effigenix.domain.masterdata.ProductCategoryId;
import de.effigenix.infrastructure.masterdata.persistence.entity.ProductCategoryEntity;
import org.springframework.stereotype.Component;

@Component
public class ProductCategoryMapper {

    public ProductCategoryEntity toEntity(ProductCategory category) {
        return new ProductCategoryEntity(
                category.id().value(),
                category.name().value(),
                category.description()
        );
    }

    public ProductCategory toDomain(ProductCategoryEntity entity) {
        return ProductCategory.reconstitute(
                ProductCategoryId.of(entity.getId()),
                new CategoryName(entity.getName()),
                entity.getDescription()
        );
    }
}
