package user

import (
	"context"
	"time"

	"go.uber.org/zap"

	domainuser "codeberg.org/mapleopentech/monorepo/cloud/maplepress-backend/internal/domain/user"
)

// GetUserUseCase handles retrieving a user by ID
type GetUserUseCase struct {
	repo   domainuser.Repository
	logger *zap.Logger
}

// ProvideGetUserUseCase creates a new GetUserUseCase
func ProvideGetUserUseCase(repo domainuser.Repository, logger *zap.Logger) *GetUserUseCase {
	return &GetUserUseCase{
		repo:   repo,
		logger: logger,
	}
}

// GetUserInput is the input for getting a user
type GetUserInput struct {
	ID string
}

// GetUserOutput is the output after getting a user
type GetUserOutput struct {
	ID        string
	Email     string
	Name      string
	CreatedAt time.Time
	UpdatedAt time.Time
}

// Execute retrieves a user by ID
func (uc *GetUserUseCase) Execute(ctx context.Context, tenantID string, input *GetUserInput) (*GetUserOutput, error) {
	uc.logger.Debug("executing get user use case",
		zap.String("tenant_id", tenantID),
		zap.String("id", input.ID))

	user, err := uc.repo.GetByID(ctx, tenantID, input.ID)
	if err != nil {
		uc.logger.Error("failed to get user", zap.Error(err))
		return nil, err
	}

	return &GetUserOutput{
		ID:        user.ID,
		Email:     user.Email,
		Name:      user.Name,
		CreatedAt: user.CreatedAt,
		UpdatedAt: user.UpdatedAt,
	}, nil
}
