<?php

namespace App\Modules\Admin\Tenancy\Controllers;

use App\Http\Controllers\Controller;
use App\Modules\Admin\Billing\Services\BillingFailedPaymentService;
use App\Modules\Admin\Tenancy\Models\Tenant;
use App\Modules\Admin\Tenancy\Requests\StoreBillingFailureRequest;
use Illuminate\Http\RedirectResponse;

class TenantBillingRecordController extends Controller
{
    public function storeFailedPayment(
        StoreBillingFailureRequest $request,
        Tenant $tenant,
        BillingFailedPaymentService $billing,
    ): RedirectResponse {
        $billing->record((int) $tenant->id, (int) $request->user()->id, [
            'reason' => (string) $request->validated('reason'),
            'reference' => $request->validated('reference'),
        ]);

        return redirect()->route('admin.operations.tenants.diagnostics', $tenant)
            ->with('status', __('operations.billing_failure_recorded'));
    }
}
