package mappers

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

func OrganizationEntityToModel(entity *entities.Organization) *models.Organization {
	if entity == nil {
		return nil
	}

	return &models.Organization{
		ID:          entity.ID,
		Name:        entity.Name,
		Email:       entity.Email,
		PhoneNumber: entity.PhoneNumber,
		PlanType:    constants.PlanType(entity.PlanType),
		CreatedAt:   entity.CreatedAt,
		UpdatedAt:   entity.UpdatedAt,
	}
}

func OrganizationModelToEntity(model *models.Organization) *entities.Organization {
	if model == nil {
		return nil
	}

	return &entities.Organization{
		ID:          model.ID,
		Name:        model.Name,
		Email:       model.Email,
		PhoneNumber: model.PhoneNumber,
		PlanType:    string(model.PlanType),
		CreatedAt:   model.CreatedAt,
		UpdatedAt:   model.UpdatedAt,
	}
}

func OrganizationEntityToResponse(entity *entities.Organization) *models.OrganizationResponse {
	if entity == nil {
		return nil
	}

	return &models.OrganizationResponse{
		ID:          entity.ID,
		Name:        entity.Name,
		Email:       entity.Email,
		PhoneNumber: entity.PhoneNumber,
		PlanType:    constants.PlanType(entity.PlanType),
		CreatedAt:   entity.CreatedAt,
		UpdatedAt:   entity.UpdatedAt,
	}
}

func OrganizationEntitiesToModels(entities []*entities.Organization) []*models.Organization {
	if entities == nil {
		return nil
	}

	models := make([]*models.Organization, len(entities))
	for i, entity := range entities {
		models[i] = OrganizationEntityToModel(entity)
	}
	return models
}

func OrganizationEntitiesToResponses(entities []*entities.Organization) []*models.OrganizationResponse {
	if entities == nil {
		return nil
	}

	responses := make([]*models.OrganizationResponse, len(entities))
	for i, entity := range entities {
		responses[i] = OrganizationEntityToResponse(entity)
	}
	return responses
}
