<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Resources\Admin\GoogleAddIndexResource;
use App\Http\Resources\Currencies\CurrencyIndexResource;
use App\Http\Resources\Golds\GoldIndexResource;
use App\Http\Resources\Silvers\SilverIndexResource;
use App\Models\Currency;
use App\Models\CurrencyPrice;
use App\Models\GoldPrice;
use App\Models\GoogleAd;
use App\Models\SilverPrice;
use App\Traits\ApiResponder;
use Carbon\Carbon;
use Illuminate\Http\Request;

class GoogleAdController extends Controller
{
    use ApiResponder;
    //
    public function index(Request $request)
    {
        // $user = Auth::user();

        $google_ads = GoogleAd::query();

        // Filter by payment method
        if ($request->has('payment_method')) {
            $payment_method = $request->input('payment_method');
            $google_ads->where('payment_method', $payment_method);
        }

        // You MUST assign get()
        $google_ads = $google_ads->orderBy('id', 'desc')->get();

        return $this->respondResource(GoogleAddIndexResource::collection($google_ads),[
             'optional_update' => $request->attributes->get('optional_update'),
        ]);
    }
}
