<?php

namespace Tests\Unit\v2\master\TestDef;

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

/**
 * Unit tests for TestDefTechModel
 * 
 * Tests the technical definition model for TEST and PARAM types
 */
class TestDefTechModelTest extends CIUnitTestCase
{
  protected TestDefTechModel $model;

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

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

  /**
   * Test model has correct primary key
   */
  public function testModelHasCorrectPrimaryKey(): void
  {
    $this->assertEquals('TestTechID', $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 key
    $this->assertContains('TestSiteID', $allowedFields);

    // Technical fields
    $this->assertContains('DisciplineID', $allowedFields);
    $this->assertContains('DepartmentID', $allowedFields);
    $this->assertContains('ResultType', $allowedFields);
    $this->assertContains('RefType', $allowedFields);
    $this->assertContains('VSet', $allowedFields);

    // Quantity and units
    $this->assertContains('ReqQty', $allowedFields);
    $this->assertContains('ReqQtyUnit', $allowedFields);
    $this->assertContains('Unit1', $allowedFields);
    $this->assertContains('Factor', $allowedFields);
    $this->assertContains('Unit2', $allowedFields);
    $this->assertContains('Decimal', $allowedFields);

    // Collection and method
    $this->assertContains('CollReq', $allowedFields);
    $this->assertContains('Method', $allowedFields);
    $this->assertContains('ExpectedTAT', $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 ResultType field is in allowed fields
   */
  public function testResultTypeFieldExists(): void
  {
    $allowedFields = $this->model->allowedFields;
    $this->assertContains('ResultType', $allowedFields);
  }

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

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

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