<?php

use App\Models\Company;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

describe('Company Model', function () {
    it('can create a company', function () {
        $company = Company::factory()->create([
            'name' => 'Test Media Company',
            'email' => 'company@example.com',
        ]);

        expect($company->name)->toBe('Test Media Company')
            ->and($company->email)->toBe('company@example.com')
            ->and($company->exists)->toBeTrue();
    });

    it('has guarded attributes', function () {
        $guarded = ['id'];

        expect(Company::make()->getGuarded())->toEqual($guarded);
    });

    it('belongs to user', function () {
        $company = Company::factory()->create();

        expect($company->user())->toBeInstanceOf(BelongsTo::class);
    });

    it('has one partner media', function () {
        $company = Company::factory()->create();

        expect($company->partnerMedia())->toBeInstanceOf(HasOne::class);
    });

    it('has many journalists through partner media', function () {
        $company = Company::factory()->create();

        expect($company->journalists())->toBeInstanceOf(HasManyThrough::class);
    });
});
