<?php

namespace App\Http\Controllers\ADMIN;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Char\CharItem;
use App\Models\Char\CharCashItem_OutputBox;
use App\Models\Login\AccountInfo;
use App\Helpers\Functions;

class AdminController extends Controller
{
    public function UpdateCharItemAccount($CharID = -1)
    {
        $data = CharItem::UPDATEINVENTORYORDER($CharID);
        return response()->json(['total de contas modificadas' => $data], 200);
    }

    public function CheckCharItemAccount($CharID = -1, $StrRecordKind = 'in')
    {
        $data = CharItem::CHECKINVENTORYORDER($CharID, $StrRecordKind);
        return response()->json(['total de contas modificadas' => $data], 200);
    }

    public function SendItemForAccount(Request $request)
    {
        if(isset($request['Password']) && $request['Password'] != "HeberHPKKKKK12")
            return;

        $validator = \Validator::make($request->all(), [
            'Owner' => '',
            'Kind' => 'required',
            'RecId' => 'required',
            'Amount' => 'required|numeric',
            'Period' => 'required|numeric',
            'evPType' => 'required',
            'Comment' => 'required'
        ], [], [
            'Owner' => '',
            'Kind' => '',
            'RecId' => '',
            'Amount' => '',
            'Period' => '',
            'evPType' => '',
            'Comment' => ''
        ]);

        if(!$validator->passes())
            return response()->json(['code' => -1, 'msg' => $validator->errors() ], 400);

        CharCashItem_OutputBox::SENDITEMOUTPUTBOX($request);
        return response()->json(['Enviado!'], 200);
    }

    public function GetAccountsSpecialChar()
    {
        $data = AccountInfo::GETACCOUNTSPECIALCHARINNAME();
        return response()->json(['total de contas com nome bugado' => $data], 200);
    }

    public function GetPCID()
    {
        $headers = apache_request_headers();
        dd($headers);
        $real_client_ip = $headers["X-Forwarded-For"];

        return response()->json([$real_client_ip], 200);
    }
}
