<?php

namespace Modules\Lpj\Models;

use Illuminate\Foundation\Auth\User;

class Noc extends Base
{
    protected $table = 'noc';

    protected $guarded = ['id'];

    protected $casts = [
        'nominal_bayar' => 'decimal:2',
        'status_bayar' => 'boolean',
        'status_kurang_bayar' => 'boolean',
        'nominal_kurang_bayar' => 'decimal:2',
        'status_lebih_bayar' => 'boolean',
        'nominal_lebih_bayar' => 'decimal:2',
        'tanggal_pembayaran' => 'date',
        'nominal_penyelesaian' => 'decimal:2',
        'status_penyelesaiaan' => 'boolean',
        'tanggal_penyelesaian' => 'date',
        'memo_penyelesaian_date' => 'date',
        'memo_penyelesaian_payment_date' => 'date',
        'memo_penyelesaian_created_at' => 'datetime',
        'status' => 'boolean',
        'authorized_status' => 'boolean',
        'authorized_at' => 'datetime',
    ];

    // Relationship with Permohonan
    public function permohonan()
    {
        return $this->belongsTo(Permohonan::class, 'permohonan_id');
    }

    // Relationship with PersetujuanPenawaran
    public function persetujuanPenawaran()
    {
        return $this->belongsTo(PersetujuanPenawaran::class, 'persetujuan_penawaran_id');
    }

    // Relationship with User (for authorized_by)
    public function authorizedBy()
    {
        return $this->belongsTo(User::class, 'authorized_by');
    }

    public function debiture(){
        return $this->belongsTo(Debiture::class,'debiture_id');
    }

    public function branch(){
        return $this->belongsTo(Branch::class,'branch_id');
    }
}
