<?php

namespace Tests\Unit\v2\master\TestDef;

use CodeIgniter\Test\CIUnitTestCase;
use App\Models\Test\TestDefGrpModel;

/**
 * Unit tests for TestDefGrpModel
 * 
 * Tests the group definition model for GROUP type tests
 */
class TestDefGrpModelTest extends CIUnitTestCase
{
  protected TestDefGrpModel $model;

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

  /**
   * Test model has correct table name
   */
  public function testModelHasCorrectTableName(): void
  {
    $this->assertEquals('testdefgrp', $this->model->table);
  }

  /**
   * Test model has correct primary key
   */
  public function testModelHasCorrectPrimaryKey(): void
  {
    $this->assertEquals('TestGrpID', $this->model->primaryKey);
  }

  /**
   * Test model uses soft deletes
   */
  public function testModelUsesSoftDeletes(): void
  {
    $this->assertTrue($this->model->useSoftDeletes);
    $this->assertEquals('EndDate', $this->model->deletedField);
  }

  /**
   * Test model has correct allowed fields
   */
  public function testModelHasCorrectAllowedFields(): void
  {
    $allowedFields = $this->model->allowedFields;

    // Foreign keys
    $this->assertContains('TestSiteID', $allowedFields);
    $this->assertContains('Member', $allowedFields);

    // Timestamp fields
    $this->assertContains('CreateDate', $allowedFields);
    $this->assertContains('EndDate', $allowedFields);
  }

  /**
   * Test model uses timestamps
   */
  public function testModelUsesTimestamps(): void
  {
    $this->assertTrue($this->model->useTimestamps);
    $this->assertEquals('CreateDate', $this->model->createdField);
  }

  /**
   * Test model return type is array
   */
  public function testModelReturnTypeIsArray(): void
  {
    $this->assertEquals('array', $this->model->returnType);
  }

  /**
   * Test model has correct skip validation
   */
  public function testModelSkipValidation(): void
  {
    $this->assertFalse($this->model->skipValidation);
  }

  /**
   * Test model has correct useAutoIncrement
   */
  public function testModelUseAutoIncrement(): void
  {
    $this->assertTrue($this->model->useAutoIncrement);
  }

  /**
   * Test TestSiteID field is in allowed fields
   */
  public function testTestSiteIDFieldExists(): void
  {
    $allowedFields = $this->model->allowedFields;
    $this->assertContains('TestSiteID', $allowedFields);
  }

  /**
   * Test Member field is in allowed fields
   */
  public function testMemberFieldExists(): void
  {
    $allowedFields = $this->model->allowedFields;
    $this->assertContains('Member', $allowedFields);
  }

  /**
   * Test CreateDate field is in allowed fields
   */
  public function testCreateDateFieldExists(): void
  {
    $allowedFields = $this->model->allowedFields;
    $this->assertContains('CreateDate', $allowedFields);
  }

  /**
   * Test EndDate field is in allowed fields
   */
  public function testEndDateFieldExists(): void
  {
    $allowedFields = $this->model->allowedFields;
    $this->assertContains('EndDate', $allowedFields);
  }
}
