<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\WhyChoose;
use App\Models\HeaderImage;
use App\Models\Founder;
use Illuminate\Support\Facades\Log;
use App\Repositories\ResponseRepository;

class ImageController extends Controller
{
    public function __construct(ResponseRepository $response) {
        $this->response = $response;
    }

    public function imageUpload(Request $request) {
        if($request->hasFile('image')) {
            switch( $request->menu ) {

                case 'imageone':
                    $uploadUrl = $this->response->cloudinaryImage($request->file('image'), 'whychoose','imageone');
                    WhyChoose::first()->update(['image_one' => $uploadUrl]);
                    return $this->response->jsonResponse(false, 'Image One Uploaded Successfully', $request->menu, 201);
                    break;

                case 'imagetwo':
                    $uploadUrl = $this->response->cloudinaryImage($request->file('image'), 'whychoose','imagetwo');
                    WhyChoose::first()->update(['image_two' => $uploadUrl]);
                    return $this->response->jsonResponse(false, 'Image Two Uploaded Successfully', $request->menu, 201);
                    break;

                case 'imagethree':
                    $uploadUrl = $this->response->cloudinaryImage($request->file('image'), 'whychoose','imagethree');
                    WhyChoose::first()->update(['image_three' => $uploadUrl]);
                    return $this->response->jsonResponse(false, 'Image Three Uploaded Successfully', $request->menu, 201);
                    break;

                case 'homepage':
                    $uploadUrl = $this->response->cloudinaryImage($request->file('image'), 'HeaderImage','homepage');
                    HeaderImage::first()->update(['image_one' => $uploadUrl]);
                    return $this->response->jsonResponse(false, 'Logo One Uploaded Successfully', $request->menu, 201);
                    break;

                case 'aboutpage':
                    $uploadUrl = $this->response->cloudinaryImage($request->file('image'), 'HeaderImage','aboutpage');
                    HeaderImage::first()->update(['image_two' => $uploadUrl]);
                    return $this->response->jsonResponse(false, 'Logo Two Uploaded Successfully', $request->menu, 201);
                    break;

                case 'servicepage':
                    $uploadUrl = $this->response->cloudinaryImage($request->file('image'), 'HeaderImage','servicepage');
                    HeaderImage::first()->update(['image_three' => $uploadUrl]);
                    return $this->response->jsonResponse(false, 'Logo Three Uploaded Successfully', $request->menu, 201);
                    break;

                case 'contactpage':
                    $uploadUrl = $this->response->cloudinaryImage($request->file('image'), 'HeaderImage','contactpage');
                    HeaderImage::first()->update(['image_four' => $uploadUrl]);
                    return $this->response->jsonResponse(false, 'Logo Four Uploaded Successfully', $request->menu, 201);
                    break;

                case 'foundersimage':
                    $uploadUrl = $this->response->cloudinaryImage($request->file('image'), 'Founder','foundersimage');
                    Founder::first()->update(['image' => $uploadUrl]);
                    return $this->response->jsonResponse(false, 'Founder Image Uploaded Successfully', $request->menu, 201);
                    break;

                case 'foundersimageone':
                    $uploadUrl = $this->response->cloudinaryImage($request->file('image'), 'Founder','foundersimageone');
                    Founder::first()->update(['founder_image_one' => $uploadUrl]);
                    return $this->response->jsonResponse(false, 'Founder Image One Uploaded Successfully', $request->menu, 201);
                    break;

                case 'foundersimagetwo':
                    $uploadUrl = $this->response->cloudinaryImage($request->file('image'), 'Founder','foundersimagetwo');
                    Founder::first()->update(['founder_image_two' => $uploadUrl]);
                    return $this->response->jsonResponse(false, 'Founder Image Two Uploaded Successfully', $request->menu, 201);
                    break;
            }
        } else {
            return $this->response->jsonResponse(true, 'Image Size is too high', [], 202);
        }
    }
}
