<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\CapitalAllowanceService;

class CapitalAllowanceController extends Controller
{
    protected $capitalAllowanceService;

    // Inject the CapitalAllowanceService
    public function __construct(CapitalAllowanceService $capitalAllowanceService)
    {
        $this->capitalAllowanceService = $capitalAllowanceService;
    }

    /**
     * Handle the request to calculate capital allowances
     */
    public function calculate(Request $request)
    {
        // Get inputs from the request
        $vehiclePrice = $request->input('vehicle_price');
        $monthOfFirstRegistration = $request->input('vehicle_purchase_date');
        $vehicleBusinessEntryDate = $request->input('vehicle_business_entry_date');
        $vehicleCO2Emission = $request->input('vehicle_co2_emission');
        $purchaseSellDate = $request->input('purchase_sell_date');

        // Use the service to calculate capital allowances
        $result = $this->capitalAllowanceService->calculateCapitalAllowances(
            $vehiclePrice,
            $monthOfFirstRegistration,
            $vehicleBusinessEntryDate,
            $vehicleCO2Emission,
            $purchaseSellDate
        );

        // Return the result
        return response()->json($result);
    }
}