<?php

namespace App\Http\Controllers\API;

use App\City;
use App\About;
use App\Http\Requests\API\VisitorMessageRequest;
use App\Http\Resources\ContactUsResource;
use App\Http\Resources\IntroScreensResource;
use App\Http\Resources\PrivacyResource;
use App\Http\Resources\ServiceResource;
use App\Http\Resources\SliderResource;
use App\Policy;
use App\Helpers\ImageHelper;
use App\Service;
use App\Slider;
use App\VisitorMessage;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use App\Http\Resources\CityResource;
use App\Http\Resources\TermsResource;
use App\Http\Resources\AboutsResource;
use App\Http\Resources\LanguagesResource;

class HomeController extends Controller
{

    /**
     * Site information like logo, about us, terms, etc...
     * @return JsonResponse
     */
    public function infoCollection() :JsonResponse
    {
        $logo = settings('website_logo') ?? 'assets/web/images/logo.png';
        $logo = ImageHelper::getFullPath($logo);
        $language = languages();
//        $screens = Screen::withDescription();
        $abouts = About::getAbout();
        $terms = Policy::terms();
        $privacy = Policy::privacy();
        $banner = Slider::withDescription(11);

        $local = getCurrentLocale();

        return response()->json([
            'message' => '',
            'data' => [
                'site_phone' => settings('site_phone'),
                'site_address' => settings('site_address'),
                'site_email' => settings('site_email'),
                'lat' => settings('lat'),
                'lng' => settings('lng'),
                'facebook' => settings('facebook'),
                'twitter' => settings('twitter'),
                'instagram' => settings('instagram'),
                'snapchat' => settings('snapchat'),
                'linkedin' => settings('linkedin'),
                'youtube' => settings('youtube'),
                'tiktok' => settings('tiktok'),
                'first_hint' => settings('consulting_requests_hint_1_'.$local),
                'second_hint' => settings('consulting_requests_hint_2_'.$local),
                'documentation_fees' => settings('documentation_fees'),
//                'added_value' => settings('added_Value'),
                'logo' => $logo,
                'languages' => LanguagesResource::collection($language),
//                'screens' => ScreensResource::make($screens),
                'abouts' => AboutsResource::make($abouts),
                'terms' => TermsResource::make($terms),
                'privacy' => PrivacyResource::make($privacy),
                'banner' => SliderResource::make($banner),
            ]
        ], 200);

    }

    public function introScreens()
    {
        $introScreens = Service::withDescription([7,8,9]);
        $data = IntroScreensResource::collection($introScreens);
        return response()->json(['message' => '', 'data' => $data], 200);
    }

    /**
     * Get services
     * @return JsonResponse
     */
    public function services() :JsonResponse
    {
        $services = Service::withDescription([1,2,3,4,5]);
        $data = ServiceResource::collection($services);
        return response()->json(['message' => '', 'data' => $data], 200);
    }

    /**
     * Get cities or city depend on id
     * @param null $city
     * @return JsonResponse
     */
    public function city($city = null) :JsonResponse
    {
        $cities = City::withDescription($city);
        if (!$cities){
            return response()->json(['message' => __('cities.no_data'), 'data' => null], 400);
        }
        $data = $city ? CityResource::make($cities) : CityResource::collection($cities);
        return response()->json(['message' => '', 'data' => $data], 200);
    }

    /**
     * Send visitor message
     * @param VisitorMessageRequest $request
     * @return JsonResponse
     */
    public function contactUs(VisitorMessageRequest $request) :JsonResponse
    {
        $data = $request->all();
//        $data['phone'] = $request->code.$request->phone;
        $contactUs = VisitorMessage::create($data);
        return response()->json(['message' => __('visitorMessages.message_success'), 'data' => ContactUsResource::make($contactUs)], 200);
    }
}
