<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class AlternatifModel extends Model
{
    protected $table = 'alternatif';
    protected $primaryKey = 'id_alternatif';
    protected $fillable = ['nama'];
    public $timestamps = false;

    public static function add_alternatif_ahp($params)
    {
        DB::table('alternatif_ahp')->insert($params);
    }

    public static function get_alternatif_ahp($id_kriteria, $id_alternatif_1, $id_alternatif_2)
    {
        return DB::table('alternatif_ahp')
            ->where('id_kriteria', $id_kriteria)
            ->where('id_alternatif_1', $id_alternatif_1)
            ->where('id_alternatif_2', $id_alternatif_2)
            ->first();
    }

    public static function delete_alternatif_ahp($id_kriteria)
    {
        DB::table('alternatif_ahp')->where('id_kriteria', $id_kriteria)->delete();
        return true;
    }

    public static function update_prioritas($id_kriteria, $params)
    {
        $nilai = $params['nilai'];
        DB::table('penilaian')->where('id_kriteria', $id_kriteria)->update(['nilai' => $nilai]);
    }

    public static function delete_penilaian($id_kriteria)
    {
        DB::table('penilaian')->where('id_kriteria', $id_kriteria)->delete();
        return true;
    }

    public static function add_penilaian($params)
    {
        DB::table('penilaian')->insert($params);
    }

}
