<?php

namespace App\Http\Controllers\Admin\Service;

use App\Models\Service;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use App\Models\ServiceProvider;
use App\Models\ServiceCustomPrice;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Http\FormRequest;
use App\DataTables\Admin\Service\ProviderDataTable;
use Exception;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

class ProviderController extends Controller {
    public function list(ProviderDataTable $dataTable) {
        $components['breadcrumb'] = (object) [
			'first' => 'Daftar Penyedia',
			'second' => 'Layanan'
		];
        $components['statuses'] = ['1' => 'Aktif', '0' => 'Nonaktif'];
        return $dataTable->render('admin.service.provider.list', $components);
    }
    public function getForm(ServiceProvider $target, Request $request) {
		if ($request->ajax() == false) abort('404');
        if ($target == true) $components['target'] = $target;
        return view('admin.service.provider.form', $components);
    }
    public function postForm(ServiceProvider $target, PostRequest $request) {
		if ($request->ajax() == false) abort('404');
        if (Auth::guard('admin')->user()->level == 'Admin') {
			return response()->json([
				'status'  => false, 
				'type'    => 'alert',
                'message' => 'Aksi tidak diperbolehkan.'
			]);
        }
		$input_data = [
            'name' 	 	           	     => escape_input($request->name),
            'provider_id'          	     => $request->provider_id,
            'provider_key'         	     => $request->provider_key,
            'provider_secret'      	     => $request->provider_secret,
            'is_refill_support'    	     => is_null($request->is_refill_support) ? '0' : '1',
			'profile_config'	         => json_encode([
				'endpoint' => $request['endpoint']['profile'],
				'request' => [
					'action'          => $request['request']['profile']['action'],
					'provider_id'     => $request['request']['profile']['provider_id'],
					'provider_key'    => $request['request']['profile']['provider_key'],
					'provider_secret' => $request['request']['profile']['provider_secret'],
				],
				'response' => [
					'balance' => $request['response']['profile']['balance']
				]
			]),
			'order_config'  => json_encode([
				'endpoint' => $request['endpoint']['order'],
				'request' => [
					'action'          => $request['request']['order']['action'],
					'provider_id'     => $request['request']['order']['provider_id'],
					'provider_key'    => $request['request']['order']['provider_key'],
					'provider_secret' => $request['request']['order']['provider_secret'],
					'service' 		  => $request['request']['order']['service'],
					'target' 		  => $request['request']['order']['target'],
					'quantity' 		  => $request['request']['order']['quantity'],
					'custom_comments' => $request['request']['order']['custom_comments'],
				],
				'response' => [
					'order_id' => $request['response']['order']['order_id']
				]
			]),
			'status_config' => json_encode([
				'endpoint' => $request['endpoint']['status'],
				'request' => [
					'action'          => $request['request']['status']['action'],
					'provider_id'     => $request['request']['status']['provider_id'],
					'provider_key'    => $request['request']['status']['provider_key'],
					'provider_secret' => $request['request']['status']['provider_secret'],
					'order_id' 		  => $request['request']['status']['order_id'],
				],
				'response' => [
					'status'      => $request['response']['status']['status'],
					'start_count' => $request['response']['status']['start_count'],
					'remains'     => $request['response']['status']['remains'],
				],
				'status_value' => [
					'pending'    => $request['status_value']['status']['pending'],
					'processing' => $request['status_value']['status']['processing'],
					'success'    => $request['status_value']['status']['success'],
					'error'      => $request['status_value']['status']['error'],
					'partial'    => $request['status_value']['status']['partial'],
				]
			]),
			'service_config' => json_encode([
				'endpoint' => $request['endpoint']['service'],
				'request' => [
					'action'          => $request['request']['service']['action'],
					'provider_id'     => $request['request']['service']['provider_id'],
					'provider_key'    => $request['request']['service']['provider_key'],
					'provider_secret' => $request['request']['service']['provider_secret'],
				],
				'response' => [
					'id'          => $request['response']['service']['id'],
					'name'        => $request['response']['service']['name'],
					'category'    => $request['response']['service']['category'],
					'description' => $request['response']['service']['description'],
					'price'       => $request['response']['service']['price'],
					'min'         => $request['response']['service']['min'],
					'max'         => $request['response']['service']['max'],
					'type'        => $request['response']['service']['type'],
					'refill'      => $request['response']['service']['refill'],
				],
				'other_value' => [
					'comment_likes'     => $request['other_value']['service']['comment_likes'],
					'custom_comments'   => $request['other_value']['service']['custom_comments'],
					'is_refill_support' => $request['other_value']['service']['is_refill_support'],
				],
				'profit_setting' => [
					'operator'   => $request['profit_setting']['service']['operator'],
					'value'      => $request['profit_setting']['service']['value'],
				],
				'price_setting' => [
					'operator'   => $request['price_setting']['service']['operator'],
					'value'      => $request['price_setting']['service']['value'],
				],
				'looping'     => $request['response']['service']['looping'],
				'currency'     => $request['currency'],
			]),
			'refill_config'  => json_encode([
				'endpoint' => $request['endpoint']['refill'],
				'request' => [
					'action'          => $request['request']['refill']['action'],
					'provider_id'     => $request['request']['refill']['provider_id'],
					'provider_key'    => $request['request']['refill']['provider_key'],
					'provider_secret' => $request['request']['refill']['provider_secret'],
					'order_id' 		  => $request['request']['refill']['order_id'],
				],
				'response' => [
					'refill_id' => $request['response']['refill']['refill_id']
				]
			]),
			'refill_status_config' => json_encode([
				'endpoint' => $request['endpoint']['refill_status'],
				'request' => [
					'action'          => $request['request']['refill_status']['action'],
					'provider_id'     => $request['request']['refill_status']['provider_id'],
					'provider_key'    => $request['request']['refill_status']['provider_key'],
					'provider_secret' => $request['request']['refill_status']['provider_secret'],
					'refill_id' 	  => $request['request']['refill_status']['refill_id'],
				],
				'response' => [
					'status'      => $request['response']['refill_status']['status'],
				],
				'status_value' => [
					'pending'    => $request['status_value']['refill_status']['pending'],
					'processing' => $request['status_value']['refill_status']['processing'],
					'success'    => $request['status_value']['refill_status']['success'],
					'error'      => $request['status_value']['refill_status']['error'],
				]
			]),
		];
		if ($target->id <> null) {
			$check_data = ServiceProvider::where([['name', $input_data['name']]])->first();
			if ($input_data['name'] <> $target['name'] AND $check_data) {
				$validator = Validator::make($request->all(), [
					'name' => 'required|unique:service_providers,name|max:20',
				], [], ['name' => 'Nama']);
				if ($validator->fails()) {
                    return response()->json([
						'status'  => false, 
						'type'    => 'validation',
						'message' => $validator->errors()->toArray()
					]);
				}
			}
			if (is_null($request->is_refill_support) == false) {
				$validator = Validator::make($request->all(), [
					'endpoint.refill'                => $request['endpoint']['refill'] <> '' ? 'required|url' : '',
					'request.refill.action'          => $request['request']['refill']['action'] <> '' ? 'required|alpha_dash' : '',
					'request.refill.provider_id'     => 'required|alpha_dash',
					'request.refill.provider_key'    => 'required|alpha_dash',
					'request.refill.provider_secret' => $request['request']['refill']['provider_secret'] <> '' ? 'required|alpha_dash' : '',
					'response.refill.refill_id'      => 'required',
		
					'endpoint.refill_status'                => $request['endpoint']['refill_status'] <> '' ? 'required|url' : '',
					'request.refill_status.action'    	    => $request['request']['refill_status']['action'] <> '' ? 'required|alpha_dash' : '',
					'request.refill_status.provider_id'     => 'required|alpha_dash',
					'request.refill_status.provider_key'    => 'required|alpha_dash',
					'request.refill_status.provider_secret' => $request['request']['refill_status']['provider_secret'] <> '' ? 'required|alpha_dash' : '',
					'request.refill_status.refill_id'       => 'required|alpha_dash',
					'response.refill_status.status' 		=> 'required',
					'status_value.refill_status.pending'    => 'required|alpha_dash',
					'status_value.refill_status.processing' => 'required|alpha_dash',
					'status_value.refill_status.success'    => 'required|alpha_dash',
					'status_value.refill_status.error'      => 'required|alpha_dash',
				], [], [
					'endpoint.refill'                => 'Endpoint (Refill Pesanan)',
					'request.refill.action'          => 'Aksi (Request - Refill Pesanan)',
					'request.refill.provider_id'     => 'ID (Request - Refill Pesanan)',
					'request.refill.provider_key'    => 'Kunci (Request - Refill Pesanan)',
					'request.refill.provider_secret' => 'Rahasia (Request - Refill Pesanan)',
					'response.refill.refill_id'      => 'ID Refill (Response - Refill Pesanan)',

					'endpoint.refill_status'                => 'Endpoint (Status Refill)',
					'request.refill_status.action'    	    => 'Aksi (Request - Status Refill)',
					'request.refill_status.provider_id'     => 'ID (Request - Status Refill)',
					'request.refill_status.provider_key'    => 'Kunci (Request - Status Refill)',
					'request.refill_status.provider_secret' => 'Rahasia (Request - Status Refill)',
					'request.refill_status.refill_id'       => 'ID Refill (Request - Status Refill)',
					'response.refill_status.status' 		=> 'Status (Response - Status Refill)',
					'status_value.refill_status.pending'    => 'Pending (Status Value - Status Refill)',
					'status_value.refill_status.processing' => 'Processing (Status Value - Status Refill)',
					'status_value.refill_status.success'    => 'Success (Status Value - Status Refill)',
					'status_value.refill_status.error'      => 'Error (Status Value - Status Refill)',
				]);
				if ($validator->fails()) {
					foreach (json_decode($validator->errors(), true) as $item) {
						$message = '<br />';
						$message .= $item[0].'';
						$message_array[] = $message;
					}
					return response()->json([
						'status'  => false, 
						'type'    => 'alert',
						'message' => 'Mohon periksa input. '.implode('', $message_array).''
					]);
					throw new HttpResponseException(response()->json([
						'status'  => false, 
						'type'    => 'alert',
						'message' => 'Mohon periksa input. '.implode('', $message_array).''
					]));
				}
			}
			$update_data = $target->update($input_data);
			return response()->json([
				'status'  => true, 
				'message' => 'Penyedia berhasil diperbarui.'
			]);
		} else {
			if (is_null($request->is_refill_support) == false) {
				$validator = Validator::make($request->all(), [
					'endpoint.refill'                => 'required|url',
					'request.refill.action'          => $request['request']['refill']['action'] <> '' ? 'required|alpha_dash' : '',
					'request.refill.provider_id'     => 'required|alpha_dash',
					'request.refill.provider_key'    => 'required|alpha_dash',
					'request.refill.provider_secret' => $request['request']['refill']['provider_secret'] <> '' ? 'required|alpha_dash' : '',
					'response.refill.refill_id'      => 'required',
		
					'endpoint.refill_status'                => 'required|url',
					'request.refill_status.action'    	    => $request['request']['refill_status']['action'] <> '' ? 'required|alpha_dash' : '',
					'request.refill_status.provider_id'     => 'required|alpha_dash',
					'request.refill_status.provider_key'    => 'required|alpha_dash',
					'request.refill_status.provider_secret' => $request['request']['refill_status']['provider_secret'] <> '' ? 'required|alpha_dash' : '',
					'request.refill_status.refill_id'       => 'required|alpha_dash',
					'response.refill_status.status' 		=> 'required',
					'status_value.refill_status.pending'    => 'required|alpha_dash',
					'status_value.refill_status.processing' => 'required|alpha_dash',
					'status_value.refill_status.success'    => 'required|alpha_dash',
					'status_value.refill_status.error'      => 'required|alpha_dash',
				], [], [
					'endpoint.refill'                => 'Endpoint (Refill Pesanan)',
					'request.refill.action'          => 'Aksi (Request - Refill Pesanan)',
					'request.refill.provider_id'     => 'ID (Request - Refill Pesanan)',
					'request.refill.provider_key'    => 'Kunci (Request - Refill Pesanan)',
					'request.refill.provider_secret' => 'Rahasia (Request - Refill Pesanan)',
					'response.refill.refill_id'      => 'ID Refill (Response - Refill Pesanan)',

					'endpoint.refill_status'                => 'Endpoint (Status Refill)',
					'request.refill_status.action'    	    => 'Aksi (Request - Status Refill)',
					'request.refill_status.provider_id'     => 'ID (Request - Status Refill)',
					'request.refill_status.provider_key'    => 'Kunci (Request - Status Refill)',
					'request.refill_status.provider_secret' => 'Rahasia (Request - Status Refill)',
					'request.refill_status.refill_id'       => 'ID Refill (Request - Status Refill)',
					'response.refill_status.status' 		=> 'Status (Response - Status Refill)',
					'status_value.refill_status.pending'    => 'Pending (Status Value - Status Refill)',
					'status_value.refill_status.processing' => 'Processing (Status Value - Status Refill)',
					'status_value.refill_status.success'    => 'Success (Status Value - Status Refill)',
					'status_value.refill_status.error'      => 'Error (Status Value - Status Refill)',
				]);
				if ($validator->fails()) {
					foreach (json_decode($validator->errors(), true) as $item) {
						$message = '<br />';
						$message .= $item[0].'';
						$message_array[] = $message;
					}
					return response()->json([
						'status'  => false, 
						'type'    => 'alert',
						'message' => 'Mohon periksa input. '.implode('', $message_array).''
					]);
					throw new HttpResponseException(response()->json([
						'status'  => false, 
						'type'    => 'alert',
						'message' => 'Mohon periksa input. '.implode('', $message_array).''
					]));
				}
			}
			$insert_data = ServiceProvider::create($input_data);
			return response()->json([
				'status'  => true, 
				'message' => 'Penyedia berhasil ditambahkan.'
			]);
		}
	}
	public function status(ServiceProvider $target, $status, Request $request) {
        if ($request->ajax() == false) abort('404');
        if (Auth::guard('admin')->user()->level == 'Admin') return (json_encode(['result' => false], JSON_PRETTY_PRINT));
        if (Arr::exists(['0', '1'], $status) == false) return (json_encode(['result' => false], JSON_PRETTY_PRINT));
        $update_data = $target->update(['status' => $status]);
        if ($update_data == true) {
            return (json_encode([
                'result'  => true,
                'message' => 'Status Penyedia <b>'.$target->name.'</b> berhasil diperbarui.'
            ], JSON_PRETTY_PRINT));
        } else {
            return (json_encode(['result' => false], JSON_PRETTY_PRINT));
        }
	}
	public function delete(ServiceProvider $target, Request $request) {
		if ($request->ajax() == false) abort('404');
        if (Auth::guard('admin')->user()->level == 'Admin') return (json_encode(['result' => false], JSON_PRETTY_PRINT));
		if ($target->delete()) {
            $service = Service::where('provider_id', $target->id)->delete();
            $custom_price = ServiceCustomPrice::all();
            foreach ($custom_price as $item) {
                $service = Service::find($item->service_id);
                if ($service == false) $item->delete();
            }
			return json_encode(['result' => true], JSON_PRETTY_PRINT);
		}
	}
	public function checkBalance(ServiceProvider $target, Request $request) {
		if ($request->ajax() == false) abort('404');
        if (Auth::guard('admin')->user()->level == 'Admin') return (json_encode(['result' => false, 'message' => 'Aksi tidak diperbolehkan.'], JSON_PRETTY_PRINT));
		if ($target->profile_config <> '') $provider_config = json_decode($target->profile_config, true);
		if (isset($provider_config) AND isset($provider_config['endpoint'])) {
			foreach ($provider_config['request'] as $key => $value) {
				if ($key == 'action') {
					$post_api['action'] = $value;
				} else {
					$post_api[$value] = $target->$key; 
				}
			}
			try {
				$curl = Http::withoutVerifying()->asForm()->post($provider_config['endpoint'], $post_api);
				Log::info($curl);
				if ($curl->ok()) {
					$curl_response = $curl->json();
					$balance = '$curl_response'.$provider_config['response']['balance'].'';
					$currency = json_decode($target->service_config, true);
					eval('$balance = '.$balance.';');
					if (isset($currency['currency']) AND $currency['currency'] == 'IDR') {
						return json_encode(['result' => true, 'message' => 'Saldo Akun: Rp '.number_format($balance,0,',','.')], JSON_PRETTY_PRINT);
					} else {
						return json_encode(['result' => true, 'message' => 'Saldo Akun: $ '.number_format($balance, 2, '.', '')], JSON_PRETTY_PRINT);
					}
				} else {
					return (json_encode(['result' => false, 'message' => $curl->json()], JSON_PRETTY_PRINT));
				}
			} catch (Exception $error) {
				Log::info($error->getMessage());
				return (json_encode(['result' => false, 'message' => $error->getMessage()], JSON_PRETTY_PRINT));
			}
		}
		return (json_encode(['result' => false, 'message' => 'Terjadi kesalahan.'], JSON_PRETTY_PRINT));
	}
}

class PostRequest extends FormRequest {
    protected function getValidatorInstance() {
		$instance = parent::getValidatorInstance();
        if ($instance->fails() == true) {
			foreach (json_decode($instance->errors(), true) as $item) {
				$message = '<br />';
				$message .= $item[0].'';
				$message_array[] = $message;
			}
			throw new HttpResponseException(response()->json([
				'status'  => false, 
				'type'    => 'alert',
				'message' => 'Mohon periksa input. '.implode('', $message_array).''
			]));
		}
        return parent::getValidatorInstance();
    }
    public function rules(Request $request) {
		if (request()->segment(5) == null) {
			return [
				'name' 	 	           		 => 'required|max:30|unique:service_providers,name',
				'provider_id'          	  	 => 'required',
				'provider_key'         		 => 'required',
				'provider_secret'      		 => 'max:200',

				'endpoint.profile'                => $request['endpoint']['profile'] <> '' ? 'required|url' : '',
				'request.profile.action'          => $request['request']['profile']['action'] <> '' ? 'required|alpha_dash' : '',
				'request.profile.provider_id'     => 'required|alpha_dash',
				'request.profile.provider_key'    => 'required|alpha_dash',
				'request.profile.provider_secret' => $request['request']['profile']['provider_secret'] <> '' ? 'required|alpha_dash' : '',
				'response.profile.balance'        => 'required',

				'endpoint.order'                => 'required|url',
				'request.order.action'          => $request['request']['order']['action'] <> '' ? 'required|alpha_dash' : '',
				'request.order.provider_id'     => 'required|alpha_dash',
				'request.order.provider_key'    => 'required|alpha_dash',
				'request.order.provider_secret' => $request['request']['order']['provider_secret'] <> '' ? 'required|alpha_dash' : '',
				'request.order.service'         => 'required|alpha_dash',
				'request.order.target'          => 'required|alpha_dash',
				'request.order.quantity'        => 'required|alpha_dash',
				'request.order.custom_comments' => $request['request']['order']['custom_comments'] <> '' ? 'required|alpha_dash' : '',
				'response.order.order_id'       => 'required',

				'endpoint.status'                => 'required|url',
				'request.status.action'    	     => $request['request']['status']['action'] <> '' ? 'required|alpha_dash' : '',
				'request.status.provider_id'     => 'required|alpha_dash',
				'request.status.provider_key'    => 'required|alpha_dash',
				'request.status.provider_secret' => $request['request']['status']['provider_secret'] <> '' ? 'required|alpha_dash' : '',
				'request.status.order_id'        => 'required|alpha_dash',
				'response.status.status' 		 => 'required',
				'response.status.start_count' 	 => 'required',
				'response.status.remains' 		 => 'required',
				'status_value.status.pending'    => 'required|alpha_dash',
				'status_value.status.processing' => 'required|alpha_dash',
				'status_value.status.success'    => 'required|alpha_dash',
				'status_value.status.error'      => 'required|alpha_dash',
				'status_value.status.partial'    => 'required|alpha_dash',

				'endpoint.service'                => 'required|url',
				'request.service.action'          => $request['request']['service']['action'] <> '' ? 'required|alpha_dash' : '',
				'request.service.provider_id'     => 'required|alpha_dash',
				'request.service.provider_key'    => 'required|alpha_dash',
				'request.service.provider_secret' => $request['request']['service']['provider_secret'] <> '' ? 'required|alpha_dash' : '',
				'response.service.id' 		      => 'required',
				'response.service.name' 	      => 'required',
				'response.service.description' 	  => $request['response']['service']['description'] <> '' ? 'required' : '',
				'response.service.price' 		  => 'required',
				'response.service.min'			  => 'required',
				'response.service.max' 		 	  => 'required',
				'response.service.type' 		  => $request['response']['service']['type'] <> '' ? 'required' : '',
				'response.service.refill' 	 	  => $request['response']['service']['refill'] <> '' ? 'required' : '',
				'currency'  					  => 'required|in:USD,IDR',
				'price_setting.service.operator'  => 'required',
				'price_setting.service.value'     => 'required',
				'profit_setting.service.operator' => 'required',
				'profit_setting.service.value'    => 'required',
				'other_value.service.comment_likes'    => $request['response']['service']['type'] <> '' ? 'required|string' : '',
				'other_value.service.custom_comments'    => $request['response']['service']['type'] <> '' ? 'required|string' : '',
				'other_value.service.is_refill_support'  => $request['response']['service']['refill'] <> '' ? 'required|string' : '',
			];
		}
		return [
            'name' 	 	          		 => 'required|max:30',
            'provider_id'          		 => 'required',
            'provider_key'         		 => 'required',
            'provider_secret'      		 => 'max:200',

			'endpoint.profile'                => $request['endpoint']['profile'] <> '' ? 'required|url' : '',
			'request.profile.action'    	  => $request['request']['profile']['action'] <> '' ? 'required|alpha_dash' : '',
			'request.profile.provider_id'     => 'required|alpha_dash',
			'request.profile.provider_key'    => 'required|alpha_dash',
			'request.profile.provider_secret' => $request['request']['profile']['provider_secret'] <> '' ? 'required|alpha_dash' : '',
			'response.profile.balance' 		  => 'required',

			'endpoint.order'                => 'required|url',
			'request.order.action'          => $request['request']['order']['action'] <> '' ? 'required|alpha_dash' : '',
			'request.order.provider_id'     => 'required|alpha_dash',
			'request.order.provider_key'    => 'required|alpha_dash',
			'request.order.provider_secret' => $request['request']['order']['provider_secret'] <> '' ? 'required|alpha_dash' : '',
			'request.order.service'         => 'required|alpha_dash',
			'request.order.target'          => 'required|alpha_dash',
			'request.order.quantity'        => 'required|alpha_dash',
			'request.order.custom_comments' => $request['request']['order']['custom_comments'] <> '' ? 'required|alpha_dash' : '',
			'response.order.order_id'       => 'required',

			'endpoint.status'                => 'required|url',
			'request.status.action'    	     => $request['request']['status']['action'] <> '' ? 'required|alpha_dash' : '',
			'request.status.provider_id'     => 'required|alpha_dash',
			'request.status.provider_key'    => 'required|alpha_dash',
			'request.status.provider_secret' => $request['request']['status']['provider_secret'] <> '' ? 'required|alpha_dash' : '',
			'request.status.order_id'        => 'required|alpha_dash',
			'response.status.status' 		 => 'required',
			'response.status.start_count' 	 => 'required',
			'response.status.remains' 		 => 'required',
			'status_value.status.pending'    => 'required|alpha_dash',
			'status_value.status.processing' => 'required|alpha_dash',
			'status_value.status.success'    => 'required|alpha_dash',
			'status_value.status.error'      => 'required|alpha_dash',
			'status_value.status.partial'    => 'required|alpha_dash',

			'endpoint.service'                => 'required|url',
			'request.service.action'          => $request['request']['service']['action'] <> '' ? 'required|alpha_dash' : '',
			'request.service.provider_id'     => 'required|alpha_dash',
			'request.service.provider_key'    => 'required|alpha_dash',
			'request.service.provider_secret' => $request['request']['service']['provider_secret'] <> '' ? 'required|alpha_dash' : '',
			'response.service.id' 		      => 'required',
			'response.service.name' 	      => 'required',
			'response.service.description' 	  => $request['response']['service']['description'] <> '' ? 'required' : '',
			'response.service.price' 		  => 'required',
			'response.service.min'			  => 'required',
			'response.service.max' 		 	  => 'required',
			'response.service.type' 		  => $request['response']['service']['type'] <> '' ? 'required' : '',
			'response.service.refill' 	 	  => $request['response']['service']['refill'] <> '' ? 'required' : '',
			'currency'  					  => 'required|in:USD,IDR',
			'price_setting.service.operator'  => 'required',
			'price_setting.service.value'     => 'required',
			'profit_setting.service.operator' => 'required',
			'profit_setting.service.value'    => 'required',
			'other_value.service.custom_comments'    => $request['response']['service']['type'] <> '' ? 'required|string' : '',
			'other_value.service.is_refill_support'  => $request['response']['service']['refill'] <> '' ? 'required|string' : '',
		];
    }
    public function attributes() {
		return [
            'name' 	 	          		 => 'Nama',
            'provider_id'          		 => 'ID',
            'provider_key'         		 => 'Kunci',
            'provider_secret'      		 => 'Rahasia',

			'endpoint.profile'                => 'Endpoint (Profile)',
			'request.profile.action'          => 'Aksi (Request - Profile)',
			'request.profile.provider_id'     => 'ID (Request - Profile)',
			'request.profile.provider_key'    => 'Kunci (Request - Profile)',
			'request.profile.provider_secret' => 'Rahasia (Request - Profile)',
			'response.profile.balance'        => 'Saldo Tersisa (Response - Profile)',

			'endpoint.order'                  => 'Endpoint (Pesanan)',
			'request.order.action'     	      => 'Aksi (Request - Pesanan)',
			'request.order.provider_id'       => 'ID (Request - Pesanan)',
			'request.order.provider_key'      => 'Kunci (Request - Pesanan)',
			'request.order.provider_secret'   => 'Rahasia (Request - Pesanan)',
			'request.order.service'           => 'ID Layanan (Request - Pesanan)',
			'request.order.target'            => 'Target (Request - Pesanan)',
			'request.order.quantity'          => 'Jumlah (Request - Pesanan)',
			'request.order.custom_comments'   => 'Komentar Khusus (Request - Pesanan)',
			'response.order.order_id' 	      => 'Saldo Tersisa (Response - Pesanan)',

			'endpoint.status'                => 'Endpoint (Status Pesanan)',
			'request.status.action'    	     => 'Aksi (Request - Status Pesanan)',
			'request.status.provider_id'     => 'ID (Request - Status Pesanan)',
			'request.status.provider_key'    => 'Kunci (Request - Status Pesanan)',
			'request.status.provider_secret' => 'Rahasia (Request - Status Pesanan)',
			'request.status.order_id'        => 'ID Pesanan (Request - Status Pesanan)',
			'response.status.status' 		 => 'Status (Response - Pesanan)',
			'response.status.start_count' 	 => 'Jumlah Awal (Response - Status Pesanan)',
			'response.status.remains' 		 => 'Jumlah Sisa (Response - Status Pesanan)',
			'status_value.status.pending'    => 'Pending (Status Value - Status Pesanan)',
			'status_value.status.processing' => 'Processing (Status Value - Status Pesanan)',
			'status_value.status.success'    => 'Success (Status Value - Status Pesanan)',
			'status_value.status.error'      => 'Error (Status Value - Status Pesanan)',
			'status_value.status.partial'    => 'Partial (Status Value - Status Pesanan)',

			'endpoint.service'                => 'Endpoint (Layanan)',
			'request.service.action'          => 'Aksi (Request - Layanan)',
			'request.service.provider_id'     => 'ID (Request - Layanan)',
			'request.service.provider_key'    => 'Kunci (Request - Layanan)',
			'request.service.provider_secret' => 'Rahasia (Request - Layanan)',
			'response.service.id' 		      => 'ID Layanan (Response - Layanan)',
			'response.service.name' 	      => 'Nama Layanan (Response - Layanan)',
			'response.service.description' 	  => 'Deskripsi Layanan (Response - Layanan)',
			'response.service.price' 		  => 'Harga Layanan (Response - Layanan)',
			'response.service.min'			  => 'Min. Layanan (Response - Layanan)',
			'response.service.max' 		 	  => 'Maks. Layanan (Response - Layanan)',
			'response.service.type' 		  => 'Tipe Layanan (Response - Layanan)',
			'response.service.refill' 	 	  => 'Refill Layanan (Response - Layanan)',
			'currency'  					  => 'Mata Uang (Price & Profit Setting - Layanan)',
			'price_setting.service.operator'  => 'Operator (Price Setting - Layanan)',
			'price_setting.service.value'     => 'Value (Price Setting - Layanan)',
			'profit_setting.service.operator' => 'Operator (Profit Setting - Layanan)',
			'profit_setting.service.value'    => 'Value (Profit Setting - Layanan)',
			'other_value.service.custom_comments'    => 'Custom Comments (Other Value - Layanan)',
			'other_value.service.comment_likes'    => 'Comment Likes (Other Value - Layanan)',
			'other_value.service.is_refill_support'  => 'Refill Support (Other Value - Layanan)',
		];
    }
}
