package auth_test

import (
	"context"
	"testing"

	"github.com/rede5/gohorsejobs/backend/internal/core/domain/entity"
	"github.com/rede5/gohorsejobs/backend/internal/core/dto"
	"github.com/rede5/gohorsejobs/backend/internal/core/usecases/auth"
)

func TestLoginUseCase_Execute_ForceChangePassword(t *testing.T) {
	// Setup Mocks (Reusing from register_candidate_test.go)
	authSvc := &MockAuthService{
		GenerateTokenFunc: func(userID, tenantID string, roles []string) (string, error) {
			return "mock-token", nil
		},
	}

	userRepo := &MockUserRepo{
		FindByEmailFunc: func(ctx context.Context, email string) (*entity.User, error) {
			return &entity.User{
				ID:           "lol-user",
				Email:        email,
				PasswordHash: "hashed_pass",
				Status:       entity.UserStatusForceChangePassword,
				Roles:        []entity.Role{},
			}, nil
		},
	}

	uc := auth.NewLoginUseCase(userRepo, authSvc)

	input := dto.LoginRequest{
		Email:    "lol@gohorsejobs.com",
		Password: "password",
	}

	resp, err := uc.Execute(context.Background(), input)

	if err != nil {
		t.Fatalf("Expected no error for force_change_password status, got %v", err)
	}

	if resp == nil {
		t.Fatal("Expected response, got nil")
	}

	if !resp.MustChangePassword {
		t.Error("Expected MustChangePassword to be true, got false")
	}
}
