package mappers

import (
	"apskel-pos-be/internal/entities"
	"apskel-pos-be/internal/models"
)

func MapIngredientCompositionEntityToModel(entity *entities.IngredientComposition) *models.IngredientComposition {
	if entity == nil {
		return nil
	}

	return &models.IngredientComposition{
		ID:                 entity.ID,
		OrganizationID:     entity.OrganizationID,
		OutletID:           entity.OutletID,
		ParentIngredientID: entity.ParentIngredientID,
		ChildIngredientID:  entity.ChildIngredientID,
		Quantity:           entity.Quantity,
		CreatedAt:          entity.CreatedAt,
		UpdatedAt:          entity.UpdatedAt,
		ParentIngredient:   MapIngredientEntityToModel(entity.ParentIngredient),
		ChildIngredient:    MapIngredientEntityToModel(entity.ChildIngredient),
	}
}

func MapIngredientCompositionModelToEntity(model *models.IngredientComposition) *entities.IngredientComposition {
	if model == nil {
		return nil
	}

	return &entities.IngredientComposition{
		ID:                 model.ID,
		OrganizationID:     model.OrganizationID,
		OutletID:           model.OutletID,
		ParentIngredientID: model.ParentIngredientID,
		ChildIngredientID:  model.ChildIngredientID,
		Quantity:           model.Quantity,
		CreatedAt:          model.CreatedAt,
		UpdatedAt:          model.UpdatedAt,
		ParentIngredient:   MapIngredientModelToEntity(model.ParentIngredient),
		ChildIngredient:    MapIngredientModelToEntity(model.ChildIngredient),
	}
}

func MapIngredientCompositionEntitiesToModels(entities []*entities.IngredientComposition) []*models.IngredientComposition {
	if entities == nil {
		return nil
	}

	models := make([]*models.IngredientComposition, len(entities))
	for i, entity := range entities {
		models[i] = MapIngredientCompositionEntityToModel(entity)
	}

	return models
}

func MapIngredientCompositionModelsToEntities(models []*models.IngredientComposition) []*entities.IngredientComposition {
	if models == nil {
		return nil
	}

	entities := make([]*entities.IngredientComposition, len(models))
	for i, model := range models {
		entities[i] = MapIngredientCompositionModelToEntity(model)
	}

	return entities
}
