<?php

namespace App\Http\Controllers;

use App\Http\Controllers\ResponseController;
use App\Http\Controllers\EncryptionController;
use App\Http\Controllers\ResourcesController;

use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;

class DelayAnalysisController extends Controller
{
    private $responseController;
    private $encController;
    private $resourcesController;

    public function __construct(){
        $this->responseController = new ResponseController();
        $this->encController = new EncryptionController();
        $this->resourcesController = new ResourcesController();
    }

    public function registerDelayAnalysis() {

    }

    public function getDelayAnalysis($line) {
        try {
            $getDelayAnalysis = DB::table('S002V01TANRE')
                ->where('ANRE_NULI', '=', $line)
                ->join('S002V01TORCO', 'ORCO_NUOR', '=', 'ANRE_NUOR')
                ->join('S002V01TPROV', 'PROV_NUPR', '=', 'ORCO_NUPR')
                ->join('S002V01TREFI', 'REFI_CRFI', '=', 'PROV_CRFI')
                ->get([
                    'ANRE_IDAR',
                    'ANRE_NUOR',
                    'ANRE_DESC',
                    'ANRE_TIPO',
                    'ANRE_FEEN',
                    'ANRE_ESTA',
                    'ANRE_USRE',
                    'ANRE_FERE',
                    'ANRE_USMO',
                    'ANRE_FEMO',

                    'ORCO_NUOR',
                    'ORCO_NUPR',
                    'ORCO_NUDE',
                    'ORCO_MONE',
                    'ORCO_COST',
                    'ORCO_PROY',

                    'PROV_NUPR',
                    'PROV_NOCO',
                    'PROV_NOMB',
                    'PROV_APPA',
                    'PROV_APMA',
                    'PROV_CORR',
                    'PROV_LAD1',
                    'PROV_TEL1',
                    'PROV_LAD2',
                    'PROV_TEL2',
                    'PROV_XRFC',
                    'PROV_XTAX',
                    'REFI_CRFI',
                    'REFI_DRFI',
                    'PROV_TIPO',
                    'PROV_SIWE',
                    'PROV_MEPA',
                ]);
        } catch (\Throwable $th) {
            return $this->responseController->makeResponse(true, "ERR_DELAY_ANALYSIS_GET000: Ocurrió un error al momento de obtener los registros", $th->getMessage(), 500);
        }

        return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $getDelayAnalysis); 
    }
}
