<?php

namespace Tests\Feature;

use App\Agent\Instructions;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

/**
 * Three headline angles, on every platform, shown before anything moves on.
 *
 * The instruction was "write at least three variations whenever Google is one
 * of the platforms", which reads as a platform workaround because that is what
 * it was: Google builds one ad from the headlines of all of them and refuses
 * fewer than three. A Meta-only campaign therefore got however many the model
 * felt like, usually one.
 *
 * One headline is a decision made on the buyer's behalf. Three angles is the
 * difference between reviewing a draft and being handed a result, which is the
 * whole point for somebody who does not buy media for a living.
 */
class ThreeHeadlinesAreWrittenEverywhereTest extends TestCase
{
    use RefreshDatabase;

    protected function setUp(): void
    {
        parent::setUp();

        $this->actingAs(User::factory()->create());
    }

    public function test_three_variations_are_asked_for_whatever_the_platform(): void
    {
        $text = app(Instructions::class)->build();

        $this->assertStringContainsString('Write three variations, whatever the platform', $text);
    }

    /**
     * The Google-only wording is gone, not merely joined by a second rule.
     *
     * Leaving it would give the model two instructions about the same thing,
     * one of which says three are only needed when Google is involved.
     */
    public function test_the_google_only_condition_is_gone(): void
    {
        $this->assertStringNotContainsString(
            'whenever Google is one of the platforms',
            app(Instructions::class)->build(),
        );
    }

    /** Google's own reason survives, because it is a real platform limit. */
    public function test_googles_reason_for_three_is_still_stated(): void
    {
        $this->assertStringContainsString('refuses fewer than three', app(Instructions::class)->build());
    }

    /**
     * Written is not the same as approved.
     *
     * Without this the copy appears and the same turn attaches creatives and
     * offers to publish, so the three angles scroll past as something that
     * already happened rather than something to choose between.
     */
    public function test_the_copy_is_shown_and_then_waits(): void
    {
        // Asserted within single lines. The prompt is a heredoc and wraps, so
        // matching across a break tests the indentation rather than the
        // instruction, which is how this first failed.
        $text = app(Instructions::class)->build();

        $this->assertStringContainsString('edited, replaced or cut to one, then wait', $text);
        $this->assertStringContainsString('attach creatives or move to publishing in the same turn', $text);
    }
}
