<?php

namespace App\Http\Controllers;

use App\Models\Payment;
use Illuminate\Http\Request;
use App\Models\Santri;
use App\Models\PaymentType;
use App\Models\DetailPayment;
use Inertia\Inertia;
use App\Services\cekDenda;
use App\Services\GenerateMonthlyBill;
use Exception;

class PaymentController extends Controller
{
    public function indexManualPayment(cekDenda $cekDenda, GenerateMonthlyBill $generateMonthlyBill)
    {
        $penalty = $cekDenda->applyPenalty();
        $bill = $generateMonthlyBill->generateAutoBill();

        $paymentType = PaymentType::pluck('payment_type');
        $nominal = PaymentType::pluck('nominal');

        $paymentPenalties = DetailPayment::with('paymentType')
            ->get()
            ->pluck('penalty', 'type_id');

        $santri = Santri::with([
            'payments.detailPayments.paymentType',
            'user'
        ])->get();

        return Inertia::render('list-admin/payment/ManualPayment', [
            'santri' => $santri,
            'penalty' => $penalty,
            'bill' => $bill,
            'fields' => [
                'nis' => 'text',
                'nama' => 'text',
                'status_santri' => 'text',
                'role_santri' => 'text',
                // 'total_penalty' => 'text',
                // 'amount_payment' => 'text',
                // 'nominal' => 'text',
                // 'payment_type' => 'select',
            ],
            'options' => [
                'payment_type' => $paymentType,
                'payment_nominal' => $nominal,
                'payment_penalty' => $paymentPenalties
            ]
        ]);
    }

    public function manualPayment(Request $request, $id)
    {
        $request->validate([
            'amount' => 'required',
            'penalty' => 'nullable'
        ], [
            'amount.required' => 'wajib mengisi nominal pembayaran',
        ]);

        try {
        } catch (Exception $e) {
        }
    }
}
