<?php

namespace App\Http\Controllers;

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

class CatalogController 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 getTaxRegimeActive($line) {

        try {
            $getTaxRegime = DB::table('S002V01TREFI')
                ->where('REFI_ESTA', '=', 'Activo')
                ->where('REFI_NULI', '=', $line)
                ->get([
                    'REFI_CRFI',
                    'REFI_NULI',
                    'REFI_DRFI',
                    'REFI_APFI',
                    'REFI_APMO',
                ]);
        } catch (\Throwable $th) {
            return $this->responseController->makeResponse(true, "ERR_CATALOG_TAXREGIME_GET000: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
        }

        $arrTaxRegime = json_decode(json_encode($getTaxRegime), true);

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

    public function getPaymentMethodActive($line) {
        try {
            $getPayment = DB::table('S002V01TMEPA')
                ->where('MEPA_ESTA', '=', 'Activo')
                ->where('MEPA_NULI', '=', $line)
                ->get([
                    'MEPA_IDME',
                    'MEPA_NOMB',
                ]);
        } catch (\Throwable $th) {
            return $this->responseController->makeResponse(true, "ERR_PAYMENT_METHOD_GET000: Ocurrió un error al momento de obtener los registros.", [], 500);
        }
        return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $getPayment);
    }

    public function getCatalogCoinsActive($line) {
        try {
            $getCatalogCoins = DB::table('S002V01TCAMO')
                ->where('CAMO_ESTA', '=', 'Activo')
                ->where('CAMO_NULI', '=', $line)
                ->get([
                    'CAMO_COMO',
                    'CAMO_NULI',
                    'CAMO_DESC',
                    'CAMO_DECI',
                    'CAMO_POVA',
                    'CAMO_FEIN',
                    'CAMO_FEFI',
                ]);
        } catch (\Throwable $th) {
            return $this->responseController->makeResponse(true, "ERR_CATALOG_COINS_GET000: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
        }

        $arrCatalogCoins = json_decode(json_encode($getCatalogCoins), true);
        return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa.", $arrCatalogCoins);
    }
}
