<?php

namespace Tests\Unit\Models;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Models\TeamMember;
use App\Models\Role;

class TeamMemberModelTest extends TestCase
{
    use RefreshDatabase;

    // 2.1.17 Unit test: TeamMember model validation
    public function test_team_member_model_validation()
    {
        $role = Role::factory()->create();

        // Test valid team member
        $teamMember = TeamMember::factory()->create([
            'role_id' => $role->id,
            'name' => 'John Doe',
            'hourly_rate' => 150.00,
            'active' => true,
        ]);

        $this->assertInstanceOf(TeamMember::class, $teamMember);
        $this->assertEquals('John Doe', $teamMember->name);
        $this->assertEquals('150.00', $teamMember->hourly_rate);
        $this->assertTrue($teamMember->active);
        $this->assertEquals($role->id, $teamMember->role_id);

        // Test casts
        $this->assertIsBool($teamMember->active);
        $this->assertIsString($teamMember->hourly_rate);
    }

    public function test_team_member_has_role_relationship()
    {
        $role = Role::factory()->create(['name' => 'Backend Developer']);
        $teamMember = TeamMember::factory()->create(['role_id' => $role->id]);

        $this->assertInstanceOf(Role::class, $teamMember->role);
        $this->assertEquals('Backend Developer', $teamMember->role->name);
    }
}
