<?php

namespace Tests\Unit;

use App\Campaigns\Platforms\LinkedInRules;
use App\Models\Campaign;
use Tests\TestCase;

class LinkedInRulesTest extends TestCase
{
    private LinkedInRules $rules;

    protected function setUp(): void
    {
        parent::setUp();
        $this->rules = new LinkedInRules;
    }

    public function test_key_and_name(): void
    {
        $this->assertSame('linkedin', $this->rules->key());
        $this->assertSame('LinkedIn', $this->rules->name());
    }

    public function test_objectives_and_minimum_budget(): void
    {
        $objectives = $this->rules->objectives();
        $this->assertContains('WEBSITE_VISITS', $objectives);
        $this->assertContains('LEAD_GENERATION', $objectives);
        $this->assertSame(10.00, $this->rules->minimumDailyBudget());
    }

    public function test_copy_limits(): void
    {
        $limits = $this->rules->copyLimits();
        $this->assertSame(70, $limits['headline']);
        $this->assertSame(100, $limits['description']);
        $this->assertSame(600, $limits['introductory_text']);
    }

    public function test_optimization_and_conversions(): void
    {
        $this->assertSame('CLICKS', $this->rules->optimizationGoal('WEBSITE_VISITS'));
        $this->assertSame('LEAD_GENERATION', $this->rules->optimizationGoal('LEAD_GENERATION'));
        $this->assertSame('PAGE_VIEW', $this->rules->conversionEvent('WEBSITE_VISITS'));
        $this->assertSame('LEAD', $this->rules->conversionEvent('LEAD_GENERATION'));
    }

    public function test_additional_problems_detects_invalid_schedule(): void
    {
        $campaign = new Campaign;
        $campaign->starts_at = now()->addDays(5);
        $campaign->ends_at = now()->addDays(2);

        $problems = $this->rules->additionalProblems($campaign);
        $this->assertContains('end date must be after the start date', $problems);
    }
}
