<?php

it('registers Slack module config endpoints and customer registration webhook config', function (): void {
    $routeFile = app_path('routes/moduleConfigRoute.php');
    $routeContent = file_get_contents($routeFile);

    expect($routeContent)->not->toBeFalse()
        ->and($routeContent)->toContain('/slack/config')
        ->and($routeContent)->toContain('/slack/config/test')
        ->and($routeContent)->toContain('/slack/config/internal-department-goal-progress')
        ->and($routeContent)->toContain('/slack/config/internal-department-goal-progress/test')
        ->and($routeContent)->toContain("requirePermission('slack_config')")
        ->and($routeContent)->toContain("(new slack())->getConfig()->getConfigRequest()")
        ->and($routeContent)->toContain("(new slack())->getConfig()->postConfigRequest()")
        ->and($routeContent)->toContain("(new slack())->test_customer_registration_webhook()")
        ->and($routeContent)->toContain("(new slack())->test_internal_department_goal_progress_webhook()")
        ->and($routeContent)->toContain("(new slack())->get_internal_department_goal_progress_config()")
        ->and($routeContent)->toContain("set_internal_department_goal_progress_config");

    $moduleContent = file_get_contents(app_path('modules/slack/slack_c.php'));
    $variableContent = file_get_contents(app_path('modules/slack/config/slack_customer_registration_webhook_url_c.php'));
    $internalWebhookContent = file_get_contents(app_path('modules/slack/config/slack_internal_department_goal_progress_webhook_url_c.php'));
    $internalDepartmentsContent = file_get_contents(app_path('modules/slack/config/slack_internal_department_ids_c.php'));
    $slackClassContent = file_get_contents(app_path('classes/slack.php'));
    $authRouteContent = file_get_contents(app_path('routes/authRoute.php'));
    $departmentsContent = file_get_contents(app_path('objects/departments_o.php'));
    $openApiContent = file_get_contents(app_path('openapi.yaml'));

    expect($moduleContent)->not->toBeFalse()
        ->and($moduleContent)->toContain("setupConfig('Slack')")
        ->and($moduleContent)->toContain('slack_customer_registration_webhook_url_c::class')
        ->and($moduleContent)->toContain('slack_internal_department_goal_progress_webhook_url_c::class')
        ->and($moduleContent)->toContain('slack_internal_department_ids_c::class')
        ->and($variableContent)->not->toBeFalse()
        ->and($variableContent)->toContain("'customer_registration_webhook_url'")
        ->and($variableContent)->toContain('Slack webhook URL used for successful customer registration notifications')
        ->and($internalWebhookContent)->not->toBeFalse()
        ->and($internalWebhookContent)->toContain("'internal_department_goal_progress_webhook_url'")
        ->and($internalDepartmentsContent)->not->toBeFalse()
        ->and($internalDepartmentsContent)->toContain("'internal_department_ids'")
        ->and($internalDepartmentsContent)->toContain('normalizeDepartmentIds')
        ->and($slackClassContent)->not->toBeFalse()
        ->and($slackClassContent)->toContain('send_customer_registration_notification')
        ->and($slackClassContent)->toContain('test_customer_registration_webhook')
        ->and($slackClassContent)->toContain('test_internal_department_goal_progress_webhook')
        ->and($slackClassContent)->toContain('get_internal_department_goal_progress_config')
        ->and($slackClassContent)->toContain('get_internal_department_goal_progress_webhook_url')
        ->and($slackClassContent)->toContain('format_customer_registration_test')
        ->and($slackClassContent)->toContain('format_internal_department_goal_progress_test')
        ->and($slackClassContent)->toContain('format_customer_registration')
        ->and($authRouteContent)->not->toBeFalse()
        ->and($authRouteContent)->toContain("AUTH_REGISTER_CVR_SLACK_NOTIFICATION_FAILED")
        ->and($departmentsContent)->not->toBeFalse()
        ->and($departmentsContent)->toContain('$slack->get_internal_department_ids()')
        ->and($departmentsContent)->toContain('$slack->get_internal_department_goal_progress_webhook_url()')
        ->and($departmentsContent)->not->toContain('select(10)->slack_webhook')
        ->and($openApiContent)->not->toBeFalse()
        ->and($openApiContent)->toContain('/slack/config')
        ->and($openApiContent)->toContain('/slack/config/test')
        ->and($openApiContent)->toContain('/slack/config/internal-department-goal-progress')
        ->and($openApiContent)->toContain('/slack/config/internal-department-goal-progress/test')
        ->and($openApiContent)->toContain('SlackConfigListResponse')
        ->and($openApiContent)->toContain('SlackInternalDepartmentGoalProgressConfigResponse')
        ->and($openApiContent)->toContain('SlackConfigTestResponse')
        ->and($openApiContent)->toContain('SlackConfigEntry');
});
