package mappers

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

func MapProductIngredientEntityToModel(entity *entities.ProductIngredient) *models.ProductIngredient {
	if entity == nil {
		return nil
	}

	return &models.ProductIngredient{
		ID:               entity.ID,
		OrganizationID:   entity.OrganizationID,
		OutletID:         entity.OutletID,
		ProductID:        entity.ProductID,
		IngredientID:     entity.IngredientID,
		Quantity:         entity.Quantity,
		WastePercentage:  entity.WastePercentage,
		CreatedAt:        entity.CreatedAt,
		UpdatedAt:        entity.UpdatedAt,
		Product:          ProductEntityToModel(entity.Product),
		Ingredient:       MapIngredientEntityToModel(entity.Ingredient),
	}
}

func MapProductIngredientModelToEntity(model *models.ProductIngredient) *entities.ProductIngredient {
	if model == nil {
		return nil
	}

	return &entities.ProductIngredient{
		ID:               model.ID,
		OrganizationID:   model.OrganizationID,
		OutletID:         model.OutletID,
		ProductID:        model.ProductID,
		IngredientID:     model.IngredientID,
		Quantity:         model.Quantity,
		WastePercentage:  model.WastePercentage,
		CreatedAt:        model.CreatedAt,
		UpdatedAt:        model.UpdatedAt,
		Product:          ProductModelToEntity(model.Product),
		Ingredient:       MapIngredientModelToEntity(model.Ingredient),
	}
}

func MapProductIngredientEntitiesToModels(entities []*entities.ProductIngredient) []*models.ProductIngredient {
	if entities == nil {
		return nil
	}

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

	return models
}

func MapProductIngredientModelsToEntities(models []*models.ProductIngredient) []*entities.ProductIngredient {
	if models == nil {
		return nil
	}

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

	return entities
}
