<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use App\Models\AlternatifModel;
use Illuminate\Support\Facades\DB;


class alternatif extends TestCase
{
    /**
     * A basic feature test example.
     */
    public function test_add_alternatif_ahp()
    {
        $params = [
            'id_kriteria' => 1,
            'id_alternatif_1' => 1,
            'id_alternatif_2' => 2,
            'nilai_1' => 1,
            'nilai_2' => 1,
        ];

        AlternatifModel::add_alternatif_ahp($params);

        $this->assertDatabaseHas('alternatif_ahp', $params);
    }
   
    public function testGetAlternatifAhp()
    {
        $params = [
            'id_kriteria' => 1,
            'id_alternatif_1' => 1,
            'id_alternatif_2' => 2,
            'nilai_1' => 1,
            'nilai_2' => 1,
        ];
        AlternatifModel::add_alternatif_ahp($params);

        $result = AlternatifModel::get_alternatif_ahp(1, 1, 2);
        $this->assertNotNull($result);
        $this->assertEquals($params['id_kriteria'], $result->id_kriteria);
       
    }

    /**
     * Test updating prioritas.
     */
    public function testUpdatePrioritas()
{
    // Insert test data
    $params = [
        'id_kriteria' => 1,
        'id_alternatif' => 1, 
        'nilai' => 10,
    ];
    AlternatifModel::add_penilaian($params);
    $newParams = [
        'nilai' => 20,
    ];
    AlternatifModel::update_prioritas(1, $newParams);

    $result = DB::table('penilaian')->where('id_kriteria', 1)->first();

    $this->assertEquals($newParams['nilai'], $result->nilai);
}

public function testDeletePenilaian()
{
    $params = [
        'id_kriteria' => 1,
        'id_alternatif' => 1, 
        'nilai' => 10,
    ];
    AlternatifModel::add_penilaian($params);
    AlternatifModel::delete_penilaian(1);
    $result = DB::table('penilaian')->where('id_kriteria', 1)->exists();

    $this->assertFalse($result);
}

}
