package mappers

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

func MapUnitEntityToModel(entity *entities.Unit) *models.Unit {
	if entity == nil {
		return nil
	}

	return &models.Unit{
		ID:             entity.ID,
		OrganizationID: entity.OrganizationID,
		OutletID:       entity.OutletID,
		Name:           entity.Name,
		Abbreviation:   entity.Abbreviation,
		IsActive:       entity.IsActive,
		DeletedAt:      entity.DeletedAt,
		CreatedAt:      entity.CreatedAt,
		UpdatedAt:      entity.UpdatedAt,
	}
}

func MapUnitModelToEntity(model *models.Unit) *entities.Unit {
	if model == nil {
		return nil
	}

	return &entities.Unit{
		ID:             model.ID,
		OrganizationID: model.OrganizationID,
		OutletID:       model.OutletID,
		Name:           model.Name,
		Abbreviation:   model.Abbreviation,
		IsActive:       model.IsActive,
		DeletedAt:      model.DeletedAt,
		CreatedAt:      model.CreatedAt,
		UpdatedAt:      model.UpdatedAt,
	}
}

func MapUnitEntitiesToModels(entities []*entities.Unit) []*models.Unit {
	if entities == nil {
		return nil
	}

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

	return models
}

func MapUnitModelsToEntities(models []*models.Unit) []*entities.Unit {
	if models == nil {
		return nil
	}

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

	return entities
}

// Entity to Response conversions
func MapUnitEntityToResponse(entity *entities.Unit) *models.UnitResponse {
	if entity == nil {
		return nil
	}

	return &models.UnitResponse{
		ID:             entity.ID,
		OrganizationID: entity.OrganizationID,
		OutletID:       entity.OutletID,
		Name:           entity.Name,
		Abbreviation:   entity.Abbreviation,
		IsActive:       entity.IsActive,
		DeletedAt:      entity.DeletedAt,
		CreatedAt:      entity.CreatedAt,
		UpdatedAt:      entity.UpdatedAt,
	}
}
