<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class RapKomisiCair extends Model
{
    protected $table = 'rap_komisi_cair';

    protected $fillable = [
        'rap_id',
        'mahasiswa_id',
        'semester',
        'nominal',
        'validasi_status',
        'catatan_validasi',
        'tanggal_validasi',
        'validasi_by',
        'status',
        'tanggal_pengajuan',
        'pengajuan_by',
        'tanggal_cair',
        'cairkan_by',
    ];

    protected $casts = [
        'tanggal_pengajuan' => 'datetime',
        'tanggal_cair' => 'datetime',
        'tanggal_validasi' => 'datetime',
    ];

    public function rap()
    {
        return $this->belongsTo(Rap::class);
    }

    public function mahasiswa()
    {
        return $this->belongsTo(Mahasiswa::class);
    }

    public function pengaju()
    {
        return $this->belongsTo(User::class, 'pengajuan_by');
    }

    public function pencair()
    {
        return $this->belongsTo(User::class, 'cairkan_by');
    }

    public function validator()
    {
        return $this->belongsTo(User::class, 'validasi_by');
    }

    // Scope untuk status approval
    public function scopePending($query)
    {
        return $query->where('status', 'pending');
    }

    public function scopeDisetujui($query)
    {
        return $query->where('status', 'disetujui');
    }

    public function scopeDitolak($query)
    {
        return $query->where('status', 'ditolak');
    }

    // Scope untuk status validasi data
    public function scopeBelumValidasi($query)
    {
        return $query->where('validasi_status', 'belum');
    }

    public function scopeValid($query)
    {
        return $query->where('validasi_status', 'valid');
    }

    public function scopeInvalid($query)
    {
        return $query->where('validasi_status', 'invalid');
    }
}
