# frozen_string_literal: true

require 'minitest/autorun'
require_relative '../lib/synor_compute'

class TestTypes < Minitest::Test
  def test_processor_type_values
    assert_equal 'cpu', SynorCompute::ProcessorType::CPU
    assert_equal 'gpu', SynorCompute::ProcessorType::GPU
    assert_equal 'tpu', SynorCompute::ProcessorType::TPU
    assert_equal 'npu', SynorCompute::ProcessorType::NPU
    assert_equal 'auto', SynorCompute::ProcessorType::AUTO
  end

  def test_precision_values
    assert_equal 'fp64', SynorCompute::Precision::FP64
    assert_equal 'fp32', SynorCompute::Precision::FP32
    assert_equal 'fp16', SynorCompute::Precision::FP16
    assert_equal 'bf16', SynorCompute::Precision::BF16
    assert_equal 'int8', SynorCompute::Precision::INT8
  end

  def test_priority_values
    assert_equal 'critical', SynorCompute::Priority::CRITICAL
    assert_equal 'high', SynorCompute::Priority::HIGH
    assert_equal 'normal', SynorCompute::Priority::NORMAL
    assert_equal 'low', SynorCompute::Priority::LOW
  end

  def test_job_status_values
    assert_equal 'pending', SynorCompute::JobStatus::PENDING
    assert_equal 'running', SynorCompute::JobStatus::RUNNING
    assert_equal 'completed', SynorCompute::JobStatus::COMPLETED
    assert_equal 'failed', SynorCompute::JobStatus::FAILED
  end

  def test_config_defaults
    config = SynorCompute::Config.new(api_key: 'test-key')
    assert_equal 'test-key', config.api_key
    assert_equal 'https://api.synor.io/compute/v1', config.base_url
    assert_equal 30, config.timeout
  end

  def test_config_custom
    config = SynorCompute::Config.new(
      api_key: 'test-key',
      base_url: 'https://custom.api.com',
      timeout: 60,
      default_processor: SynorCompute::ProcessorType::GPU
    )
    assert_equal 'https://custom.api.com', config.base_url
    assert_equal 60, config.timeout
  end

  def test_matmul_options_to_hash
    options = SynorCompute::MatMulOptions.new(
      precision: SynorCompute::Precision::FP16,
      processor: SynorCompute::ProcessorType::GPU
    )
    hash = options.to_h
    assert_equal 'fp16', hash[:precision]
    assert_equal 'gpu', hash[:processor]
  end

  def test_inference_options_defaults
    options = SynorCompute::InferenceOptions.new
    assert_equal 256, options.max_tokens
    assert_in_delta 0.7, options.temperature, 0.001
    assert_in_delta 0.9, options.top_p, 0.001
    assert_equal 50, options.top_k
  end

  def test_job_result_success
    result = SynorCompute::JobResult.new(
      job_id: 'job-123',
      status: SynorCompute::JobStatus::COMPLETED,
      result: 'output'
    )
    assert result.success?
    refute result.failed?
  end

  def test_job_result_failure
    result = SynorCompute::JobResult.new(
      job_id: 'job-456',
      status: SynorCompute::JobStatus::FAILED,
      error: 'Error message'
    )
    refute result.success?
    assert result.failed?
  end

  def test_model_info_formatted_parameters
    model = SynorCompute::ModelInfo.new(
      id: 'test',
      name: 'Test Model',
      category: 'llm',
      parameters: 70_000_000_000
    )
    assert_equal '70B', model.formatted_parameters
  end
end
