<?php

namespace Modules\Lpj\Models;

use Illuminate\Database\Eloquent\Model;
use Modules\Lpj\Models\TujuanPenilaianKJPP;
use Modules\Lpj\Models\PenawaranDetailTender;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany; // andy add

class PenawaranTender extends Model
{
    use HasFactory;

    /**
     * The attributes that are mass assignable.
     */
    protected $table = 'penawaran';

    protected $guarded = ['id'];

    // andy add
    public function penawarandetails(): HasMany
    {
        return $this->hasMany(PenawaranDetailTender::class, 'penawaran_id', 'id')->where('status', '=', 1);
    }

    public function detail(){
        return $this->belongsTo(PenawaranDetailTender::class, 'id', 'penawaran_id')->where('status', 1);
    }
    // andy add

    public function emailTenderLog(): HasMany
    {
        return $this->hasMany(PenawaranEmailTenderLog::class, 'penawaran_id', 'id');
    }

    public function penawaranKjpp()
    {
        return $this->hasMany(PenawaranDetailTender::class, 'penawaran_id');
    }

    // menambahkan relasi tujuan penilaian KJPP
    public function tujuanPenilaianKjpp()
    {
        return $this->belongsTo(TujuanPenilaianKJPP::class, 'tujuan_penilaian_kjpp_id', 'id');
    }

    public function permohonan()
    {
        return $this->belongsTo(Permohonan::class, 'nomor_registrasi', 'nomor_registrasi');
    }

    public function jenisLaporan()
    {
        return $this->belongsTo(JenisLaporan::class, 'jenis_laporan_id', 'id');
    }

    public function persetujuan(){
        return $this->belongsTo(PersetujuanPenawaran::class, 'id', 'penawaran_id');
    }

    public function penilaian(){
        return $this->belongsTo(Penilaian::class, 'nomor_registrasi', 'nomor_registrasi');
    }

    public function persetujuan_penawaran(){
        return $this->belongsTo(PersetujuanPenawaran::class, 'id', 'penawaran_id');
    }
}
