<?php

namespace App\Service;
use DB;
use App\Models\User;
use App\Models\UserOrganisation;

class ProfileService
{

	public function getuser($id){
		$user = User::where('id',$id)
			->with('address','address.country','address.state','address.city','bank_details','documents')
			// ->with('active_organisation')
			->first();

		// $user_organisation=UserOrganisation::where('user_id',$user['id'])
		// 	->where('organisation_id',$user['active_organisation'])
		// 	->with('roles')->first();

		// $user['permissions']=$user_organisation['roles'];
		// $user['is_admin']=$user_organisation['is_owner']==1?true:false;

		return $user;
	}

	public function createupdateProfile($user,$request){
		$data=[
			// 
			// 'payment_terms','gst_no','first_name','last_name','salutation','work_phone','is_customer','is_vendor',
			// 'place_of_supply','tax_preference','currency','customer_note','upload_documents',
			// 'opening_balance','department','designation','remarks','business_leagal_name','departments','status',
			// 'gender','d_o_b','citizenship','blood_group','relation_id','relationship','photo','food_type','family_ids',

			'unique_id','name','display_name','first_name','last_name','company_name','salutation','work_phone','email','mobile_no',
			'whatsapp_no','image','module_type',
			// Registration info
			'registration_type','registration_date','company_type','date_of_incorporation','company_email','company_number','website',
			// Registration No.
			'business_reg_no','gst_no','pan_no',
			// Business Classification
			'industry_sector','business_nature','year_in_business','employee_count',
			// Financial information
			'annual_turnover','insurance_coverage','authorized_capital','paid_up_capital','security_deposit',
			// Logistics Capabilities
			'service_type','service_modes','coverage_areas','specializations','insurance_options','fleet_size','daily_ship_capacity',
			// Technical Information
			'gps_tracking_enabled','api_integration','fleet_management_software','warehouse_management_system','erp_system',
			// Documents
			'id_proof_upload','address_proof_upload',
			// Customer Preferences
			'communication_type','notification_type','language_type','service_type','preferred_carrier','distance','price',
			// Other
			'ratings','is_disabled','status','registration_no_array',

			// Users Roles
			'is_customer','is_vendor','is_user','is_admin'

		];
		foreach ($data as $key => $value) {
			if(isset($request[$value]) && $request[$value]!=null && $request[$value]!=''){
				$user[$value]=$request[$value];
			}
		}

		// $user=User::create($obj);
		return $user;
	}
}