<?php

namespace App\Core\Service;

use App\Core\Repository\Product\ProductParameterMappingRepository;
use App;
use Illuminate\Support\Facades\Log;
use Exception;
use App\Exceptions\ApiErrorException;

class ProductParameterMappingService
{
    private $productParameterMappingRepository;

    public function __construct(
        ProductParameterMappingRepository $productParameterMappingRepository
    )
    {
        $this->productParameterMappingRepository = $productParameterMappingRepository;
    }

    public function select($param = [], $column = ['*'])
    {
        $response = ['status' => -1, 'message' => '', 'data' => null];

        try {
            $data = $this->productParameterMappingRepository->findByCriteria($param, $column);
            $response = [
                'status' => true,
                'data' => $data,
            ];

        } catch (ApiErrorException $e) {
            $response['message'] = $e->getMessage();
        } catch (Exception $e) {
            $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
            Log::error($message);
            $response['message'] = $e->getMessage();
        }

        return output($response);
    }
}
