<?php

namespace Tests\Unit;

use App\Models\Tag;

trait TagsTrait
{
    //abstract protected function getModel();
    abstract protected function getClassname();

    public function test_an_object_can_have_many_tags()
    {
        $object = $this->getModel();
        $tag = Tag::factory()->create();

        $object->tags()->attach($tag);

        $object->refresh();

        $this->assertEquals(1, $object->tags()->count());
        $this->assertInstanceOf(Tag::class, $object->tags()->first());
        $this->assertEquals($tag->id, $object->tags()->first()->id);
    }

    public function test_a_tag_can_be_added_to_an_object()
    {
        $object = $this->getModel();
        $tag = Tag::factory()->create();

        $object->addTag($tag);
        $object->refresh();

        $this->assertEquals(1, $object->tags()->count());
        $this->assertEquals($tag->id, $object->tags()->first()->id);

        $object->addTag($tag);
        $this->assertEquals(1, $object->tags()->count());
    }

    public function test_a_tag_can_be_an_excluded_tag_for_an_object()
    {
        $object = $this->getModel();
        $tag = Tag::factory()->create();

        $object->addTag($tag, true);
        $object->refresh();

        $this->assertEquals(1, $object->tags()->count());
        $this->assertEquals($tag->id, $object->tags()->first()->id);
        $this->assertEquals(1, $object->tags->first()->pivot->exclude);
    }
}
