<?php

namespace App\Http\Controllers;

use App\Http\Requests\CapFinanceRequest;
use App\Http\Requests\FinanceRequest;
use Illuminate\Http\Response;
use Mtc\MercuryDataModels\Dealership;
use Mtc\MercuryDataModels\Services\FinanceService;
use Mtc\MercuryDataModels\Vehicle;

class FinanceController extends Controller
{
    public function store(FinanceRequest $request, Vehicle $vehicle, FinanceService $service): Response
    {
        return response($service->get($vehicle, $request->validated()));
    }

    public function getForCap(CapFinanceRequest $request, FinanceService $service): Response
    {
        $dealership = $request->input('dealership_id')
            ? Dealership::find($request->input('dealership_id'))
            : null;

        return response($service->getForCapId(
            $request->input('cap_id'),
            $request->input('price'),
            $request->input('term'),
            $request->input('deposit'),
            $request->input('annual_mileage'),
            $request->input('credit_rating'),
            $request->input('product_type'),
            $dealership,
        ));
    }
}
