package mappers

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

func VendorEntityToModel(entity *entities.Vendor) *models.Vendor {
	if entity == nil {
		return nil
	}

	return &models.Vendor{
		ID:             entity.ID,
		OrganizationID: entity.OrganizationID,
		Name:           entity.Name,
		Email:          entity.Email,
		PhoneNumber:    entity.PhoneNumber,
		Address:        entity.Address,
		ContactPerson:  entity.ContactPerson,
		TaxNumber:      entity.TaxNumber,
		PaymentTerms:   entity.PaymentTerms,
		Notes:          entity.Notes,
		IsActive:       entity.IsActive,
		CreatedAt:      entity.CreatedAt,
		UpdatedAt:      entity.UpdatedAt,
	}
}

func VendorModelToEntity(model *models.Vendor) *entities.Vendor {
	if model == nil {
		return nil
	}

	return &entities.Vendor{
		ID:             model.ID,
		OrganizationID: model.OrganizationID,
		Name:           model.Name,
		Email:          model.Email,
		PhoneNumber:    model.PhoneNumber,
		Address:        model.Address,
		ContactPerson:  model.ContactPerson,
		TaxNumber:      model.TaxNumber,
		PaymentTerms:   model.PaymentTerms,
		Notes:          model.Notes,
		IsActive:       model.IsActive,
		CreatedAt:      model.CreatedAt,
		UpdatedAt:      model.UpdatedAt,
	}
}

func VendorEntityToResponse(entity *entities.Vendor) *models.VendorResponse {
	if entity == nil {
		return nil
	}

	return &models.VendorResponse{
		ID:             entity.ID,
		OrganizationID: entity.OrganizationID,
		Name:           entity.Name,
		Email:          entity.Email,
		PhoneNumber:    entity.PhoneNumber,
		Address:        entity.Address,
		ContactPerson:  entity.ContactPerson,
		TaxNumber:      entity.TaxNumber,
		PaymentTerms:   entity.PaymentTerms,
		Notes:          entity.Notes,
		IsActive:       entity.IsActive,
		CreatedAt:      entity.CreatedAt,
		UpdatedAt:      entity.UpdatedAt,
	}
}

func VendorEntitiesToModels(entities []*entities.Vendor) []*models.Vendor {
	if entities == nil {
		return nil
	}

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

func VendorEntitiesToResponses(entities []*entities.Vendor) []*models.VendorResponse {
	if entities == nil {
		return nil
	}

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