<?php



namespace App\Http\Controllers;



use Illuminate\Http\Request;

use App\Models\CustomDesign;
use Illuminate\Support\Facades\Mail;
use App\Mail\CustomDesignMail;


class CustomDesignController extends Controller

{

   public function store(Request $request)

{
    try {
        $request->validate([

            'company'   => 'required',

            'full_name' => 'required',

            'email'     => 'required|email',

            'phone'     => 'required',
        ]);

        $imageName = null;

        if ($request->hasFile('image')) {

            $file = $request->file('image');

            $imageName = time().'_'.$file->getClientOriginalName();

            $file->move(public_path('uploads'), $imageName);

        }

        $data = CustomDesign::create([

            'company' => $request->company,

            'full_name' => $request->full_name,

            'email' => $request->email,

            'phone' => $request->phone,

            'reference_number' => $request->reference_number,

            'project_details' => $request->project_details,

            'timeframe' => $request->timeframe,

            'finger_size' => $request->finger_size,

            'metal' => $request->metal,

            'center_shape_size' => $request->center_shape_size,

            'image' => $imageName,

        ]);

            // Admin ko mail
        //    Mail::to('aartisarathe61@gmail.com')->send(new CustomDesignMail($data));
         Mail::to('customerservice@brillianttouchllc.com')->send(new CustomDesignMail($data));
    // ->cc('arti@braintreeproducts.com')
    

            // User ko mail
            Mail::to($request->email)->send(new CustomDesignMail($data));

            return response()->json([

                'status' => true,

                'message' => 'Saved successfully'

            ]);



    } catch (\Exception $e) {



        return response()->json([

            'status' => false,

            'message' => $e->getMessage()

        ], 500);

    }

}

}