package user

import (
	"context"
	"errors"

	"github.com/rede5/gohorsejobs/backend/internal/core/ports"
)

type DeleteUserUseCase struct {
	userRepo ports.UserRepository
}

func NewDeleteUserUseCase(uRepo ports.UserRepository) *DeleteUserUseCase {
	return &DeleteUserUseCase{
		userRepo: uRepo,
	}
}

func (uc *DeleteUserUseCase) Execute(ctx context.Context, userID, tenantID string) error {
	// 1. Verify User exists and belongs to Tenant
	user, err := uc.userRepo.FindByID(ctx, userID)
	if err != nil {
		return err
	}

	if user.TenantID != tenantID {
		return errors.New("user not found in this tenant")
	}

	// 2. Delete
	return uc.userRepo.Delete(ctx, userID)
}
