#include "..\script_component.hpp"

/*
 * Author: IDSolutions
 * Repairs the vehicle
 *
 * Arguments:
 * 0: Vehicle <OBJECT> - The vehicle to repair
 * 1: Vehicle Type <STRING> - The classname of vehicle to repair
 *
 * Return Value:
 * None
 *
 * Example:
 * [vehicle, "B_APC_Tracked_01_CRV_F"] call forge_client_service_fnc_repair;
 *
 * Public: No
 */

params ["_veh", "_vehType"];

private _store = missionNamespace getVariable ["FORGE_ORG_STORE_REG", createHashMap];
private _org = _store call ["getOrg", []];

if (_org isEqualTo nil) exitWith {
    ["You are not in an organization!", "warning", 3] call EFUNC(misc,notify);
};

private _orgFunds = _org get "funds";

private _fnc_calculateRepairCost = {
    params ["_damage", "_repairPrice"];
    private _laborHours = _damage * 10;
    private _laborCost = _laborHours * _repairPrice;
    private _partsCost = _damage * 1000;
    [_laborHours, _laborCost, _partsCost, _laborCost + _partsCost]
};

private _currentDamage = damage _veh;
private _repairPrice = "REPAIR_COST" call BFUNC(getParamValue);
private _repairDetails = [_currentDamage, _repairPrice] call _fnc_calculateRepairCost;

_repairDetails params ["_laborHours", "_laborCost", "_partsCost", "_repairCost"];

private _formattedLaborHours = _laborHours toFixed 1;
private _formattedLaborCost = (_laborCost) call EFUNC(misc,formatNumber);
private _formattedPartsCost = (_partsCost) call EFUNC(misc,formatNumber);
private _formattedTotalCost = (_repairCost) call EFUNC(misc,formatNumber);

[format ["SERVICE DEPARTMENT:
    <br/>The repair will take %1 Labor Hours to complete.
    <br/>Labor Cost: $%2
    <br/>Parts Cost: $%3
    <br/>Total Cost: $%4", 
    _formattedLaborHours, _formattedLaborCost, _formattedPartsCost, _formattedTotalCost], "blue-grey", 3] call EFUNC(misc,notify);

uiSleep 5;

if (_orgFunds < _repairCost) exitWith {
    ["Insufficient organization funds for repairing.", "warning", 3] call EFUNC(misc,notify);
};

_veh vehicleChat "Repairing...";
uiSleep _laborHours;

_veh setDamage 0;
_veh vehicleChat format ["%1 Repaired.", _vehType];

_repairCost