/home/bdqbpbxa/api-uniferx.goodface.com.ua/app/Http/Controllers/Api/PageController.php
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Requests\SendFormRequest;
use App\Http\Resources\Pages\About\AboutResource;
use App\Http\Resources\Pages\About\Employees\EmployeeCollection;
use App\Http\Resources\Pages\AnonymousFeedbackResource;
use App\Http\Resources\Pages\Blog\BlogResource;
use App\Http\Resources\Pages\Blog\PostCollection;
use App\Http\Resources\Pages\Blog\PostResource;
use App\Http\Resources\Pages\Career\CareerResource;
use App\Http\Resources\Pages\Career\VacancyCollection;
use App\Http\Resources\Pages\Career\VacancyResource;
use App\Http\Resources\Pages\Catalogs\CatalogCollection;
use App\Http\Resources\Pages\Catalogs\FlyerCollection;
use App\Http\Resources\Pages\Contacts\ContactsPageResource;
use App\Http\Resources\Pages\Countries\CountryListCollection;
use App\Http\Resources\Pages\GeneralTranslationResource;
use App\Http\Resources\Pages\HomepageResource;
use App\Http\Resources\Pages\LegalInfoResource;
use App\Http\Resources\Pages\Products\ProductCollection;
use App\Http\Resources\Pages\Products\ProductPageResource;
use App\Http\Resources\Pages\Products\ProductResource;
use App\Http\Resources\Pages\Resource\CropNutritionProgramsResource;
use App\Http\Resources\Pages\Resource\CropsCollection;
use App\Http\Resources\Pages\Resource\CropsResource;
use App\Http\Resources\Pages\Resource\InformationMaterialsResource;
use App\Http\Resources\Pages\Resource\ResourcesResource;
use App\Http\Resources\Pages\Resource\TrialResultsResource;
use App\Http\Resources\Pages\TermsConditions\TermsConditionsResource;
use App\Mail\SendForm;
use App\Mail\SubscribeNews;
use App\Models\Catalog;
use App\Models\Country;
use App\Models\Crop;
use App\Models\Employee;
use App\Models\Flyer;
use App\Models\Language;
use App\Models\Page;
use App\Models\Post;
use App\Models\Product;
use App\Models\Vacancy;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage;

class PageController extends Controller
{
    public string|null $language;
    public string|null $country;
    public function __construct(Request $request)
    {
        $this->language = $request->language;
        $this->country = $request->country;
    }

    /**
     * @OA\Get(
     *  path="/pages/blog",
     *  operationId="getBlogPage",
     *  tags={"Pages"},
     *  summary="Blog page",
     *  description="Research, News & Events",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/BlogResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function blog(Request $request): JsonResponse
    {
        return  $this->page('Blog', BlogResource::class);
    }

    /**
     * @OA\Get(
     *  path="/pages/career",
     *  operationId="getCareerPage",
     *  tags={"Pages"},
     *  summary="Career page",
     *  description="Career",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/CareerResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function career(Request $request): JsonResponse
    {
        return  $this->page('Career', CareerResource::class);
    }

    /**
     * @OA\Get(
     *  path="/pages/resources",
     *  operationId="getResourcesPage",
     *  tags={"Pages"},
     *  summary="Resources page",
     *  description="Resources",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/ResourcesResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function resources(Request $request): JsonResponse
    {
        return  $this->page('Resources', ResourcesResource::class);
    }

    /**
     * @OA\Get(
     *  path="/pages/resources/crop-nutrition-programs",
     *  operationId="getCropNutritionProgramsPage",
     *  tags={"Pages"},
     *  summary="Crop Nutrition Programs page",
     *  description="Crop Nutrition Programs",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/CropNutritionProgramsResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function crop_nutrition_programs(Request $request): JsonResponse
    {
        return  $this->page('Crop nutrition programs', CropNutritionProgramsResource::class);
    }




//    /**
//     * @OA\Get(
//     *  path="/pages/resources/crop-nutrition-programs/{slug}",
//     *  operationId="getCropNutrition",
//     *  tags={"Resources"},
//     *  summary="Detailed page of crop nutrition",
//     *  description="Detailed page of crop nutrition",
//     *  @OA\Parameter(name="slug",in="path",description="Crop slug", required=true, example="cereals", @OA\Schema(type="string")),
//     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
//     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
//     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
//     *      @OA\Property(property="status", type="string", example="success"),
//     *      @OA\Property(property="data", type="object", ref="#/components/schemas/CropsResource"),
//     *  ),),
//     *  @OA\Response(response=401,description="Unauthenticated",),
//     * )
//     */
    public function nutrition_crop(Request $request): JsonResponse
    {
        $crop = Crop::query()->where('slug', $request->slug)->first();
        return $this->responseSuccess('success', CropsResource::make($crop, $this->language, $this->country, true, 'nutrition'));
    }

    /**
     * @OA\Get(
     *  path="/pages/resources/trail-results",
     *  operationId="getTrailResultsPage",
     *  tags={"Pages"},
     *  summary="Trial results page",
     *  description="Trial results page",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/TrialResultsResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function trail_results(Request $request): JsonResponse
    {
        return  $this->page('Trial results', TrialResultsResource::class);
    }

    /**
     * @OA\Get(
     *  path="/pages/resources/information-materials",
     *  operationId="getInformationMaterials",
     *  tags={"Pages"},
     *  summary="Information Materials page",
     *  description="Information Materials page",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/InformationMaterialsResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function information_materials(Request $request): JsonResponse
    {
        return  $this->page('Information materials', InformationMaterialsResource::class);
    }

    /**
     * @OA\Get(
     *  path="/pages/resources/information-materials/{id}/flyers",
     *  operationId="getCatalogFlyers",
     *  tags={"Pages"},
     *  summary="Get catalog Flyers",
     *  description="Get catalog Flyers",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="id",in="path",description="Catalog id", required=true, example="1", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="data", type="array",
     *          @OA\Items(type="object", ref="#/components/schemas/FlyerResource")
     *      ),
     *      @OA\Property(property="next", type="boolean", example="true"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function catalogFlyers(Request $request)
    {
        $catalog = Catalog::query()->find($request->id);
        if (!$catalog) return $this->responseError();
        $flyers = $catalog->flyers()->paginate($request->limit ?? 10);
        return [
            'data' => FlyerCollection::make($flyers->items())->country($this->country)->language($this->language),
            'next' => $flyers->currentPage() < $flyers->lastPage(),
        ];
    }

//    /**
//     * @OA\Get(
//     *  path="/pages/resources/trail-results/{slug}",
//     *  operationId="getTrialResultCrop",
//     *  tags={"Resources"},
//     *  summary="Detailed trial results page",
//     *  description="Detailed trial results page",
//     *  @OA\Parameter(name="slug",in="path",description="Crop slug", required=true, example="cereals", @OA\Schema(type="string")),
//     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
//     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
//     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
//     *      @OA\Property(property="status", type="string", example="success"),
//     *      @OA\Property(property="data", type="object", ref="#/components/schemas/CropsResource"),
//     *  ),),
//     *  @OA\Response(response=401,description="Unauthenticated",),
//     * )
//     */
    public function trial_crop(Request $request): JsonResponse
    {
        $crop = Crop::query()->where('slug', $request->slug)->first();
        return $this->responseSuccess('success', CropsResource::make($crop, $this->language, $this->country, true, 'trials'));
    }

    /**
     * @OA\Get(
     *  path="/pages/products",
     *  operationId="getProductsPage",
     *  tags={"Pages"},
     *  summary="Products page",
     *  description="Products page",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/ProductPageResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function products(Request $request): JsonResponse
    {
        return  $this->page('Products', ProductPageResource::class);
    }

    /**
     * @OA\Get(
     *  path="/pages/homepage",
     *  operationId="getHomepage",
     *  tags={"Pages"},
     *  summary="Homepage page",
     *  description="Homepage page",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/HomepageResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function homepage(Request $request): JsonResponse
    {
        return  $this->page('Homepage', HomepageResource::class);
    }

    /**
     * @OA\Get(
     *  path="/pages/contacts",
     *  operationId="getContacts",
     *  tags={"Pages"},
     *  summary="Contacts page",
     *  description="Contacts page",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/ContactsPageResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function contacts(Request $request): JsonResponse
    {
        return  $this->page('Contacts', ContactsPageResource::class);
    }

    /**
     * @OA\Get(
     *  path="/pages/terms-conditions",
     *  operationId="getTermsConditions",
     *  tags={"Pages"},
     *  summary="Terms Conditions page",
     *  description="Terms Conditions page",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/TermsConditionsResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function termsConditions(Request $request): JsonResponse
    {
        return  $this->page('Terms Conditions', TermsConditionsResource::class);
    }

    /**
     * @OA\Get(
     *  path="/pages/anonymous-feedback",
     *  operationId="getAnonymousFeedback",
     *  tags={"Pages"},
     *  summary="Anonymous Feedback page",
     *  description="Anonymous Feedback page",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/AnonymousFeedbackResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function anonymousFeedback(Request $request): JsonResponse
    {
        return  $this->page('Anonymous feedback', AnonymousFeedbackResource::class);
    }

    /**
     * @OA\Get(
     *  path="/pages/general-translation",
     *  operationId="getGeneralTranslation",
     *  tags={"Pages"},
     *  summary="General Translation page",
     *  description="General Translation page",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/GeneralTranslationResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function generalTranslation(Request $request): JsonResponse
    {
        return  $this->page('General Translations', GeneralTranslationResource::class);
    }

    /**
     * @OA\Get(
     *  path="/pages/legal-info",
     *  operationId="getLegalInfo",
     *  tags={"Pages"},
     *  summary="Legal info page",
     *  description="Legal info page",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/LegalInfoResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function legalInfo(Request $request): JsonResponse
    {
        return  $this->page('Legal info', LegalInfoResource::class);
    }

    /**
     * @OA\Get(
     *  path="/pages/about",
     *  operationId="getAbout",
     *  tags={"Pages"},
     *  summary="About page",
     *  description="About page",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/AboutResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function aboutUs(Request $request): JsonResponse
    {
        return  $this->page('About us', AboutResource::class);
    }

    public function page($page, $resource, $with = []): JsonResponse
    {
        $page = Page::query()->where('name', $page)->with($with)->first();
        if ($page) {
            return $this->responseSuccess('success', $resource::make($page, $this->language, $this->country));
        }
        return $this->responseError();
    }


    /**
     * @OA\Get(
     *  path="/products",
     *  operationId="getProducts",
     *  tags={"Products"},
     *  summary="Products list",
     *  description="Products list",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="page",in="query",description="Page number", required=false, example="1", @OA\Schema(type="integer")),
     *  @OA\Parameter(name="limit",in="query",description="Limit items", required=false, example="4", @OA\Schema(type="integer")),
     *  @OA\Parameter(name="all",in="query",description="Get all items", required=false, example="false", @OA\Schema(type="bool")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/ProductResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function getProducts(Request $request)
    {
        $products = Product::query()
            ->where('is_enabled', true);
        if ($request->all && $request->all === 'true') {
            $products = $products->get();
            return ProductCollection::make($products)->country($this->country)->language($this->language)->full(false);
        } else {
            $products = $products
                ->where('type', 'product')->paginate($request->limit ?? 10);
            return [
                'data' => ProductCollection::make($products->items())->country($this->country)->language($this->language)->full(false),
                'next' => $products->currentPage() < $products->lastPage(),
            ];
        }
    }

    /**
     * @OA\Get(
     *  path="/products/{slug}",
     *  operationId="getProductBySlug",
     *  tags={"Products"},
     *  summary="Detailed product page",
     *  description="Detailed product page",
     *  @OA\Parameter(name="slug",in="path",description="Product slug", required=true, example="wuxal", @OA\Schema(type="string")),
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/ProductResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function product(Request $request): JsonResponse
    {
        $product = Product::query()->where('slug', $request->slug)->where('is_enabled', true)->first();
        if (!$product) return $this->responseError();
        return $this->responseSuccess('success', ProductResource::make($product, $this->language, $this->country, true));
    }

    /**
     * @OA\Get(
     *  path="/products/{slug}/related",
     *  operationId="getRelatedProductBySlug",
     *  tags={"Products"},
     *  summary="Related products",
     *  description="Related products",
     *  @OA\Parameter(name="slug",in="path",description="Product slug", required=true, example="wuxal", @OA\Schema(type="string")),
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="limit",in="query",description="Items limit", required=false, example="10", @OA\Schema(type="integer")),
     *  @OA\Parameter(name="page",in="query",description="Page number", required=false, example="1", @OA\Schema(type="integer")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/ProductResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function productRelated(Request $request): JsonResponse
    {
        $product = Product::query()->where('slug', $request->slug)->where('is_enabled', true)->first();
        if (!$product) return $this->responseError();
        $products = $product->related_products()->where('is_enabled', true)->paginate($request->limit ?? 2);
//        dd($products);
        $products = [
            'data' => ProductCollection::make($products->items())->country($this->country)->language($this->language)->full(false),
            'next' => $products->currentPage() < $products->lastPage(),
        ];
        return $this->responseSuccess('success', $products);
    }
//    public function productNutritionProgram(Request $request): JsonResponse
//    {
//        $product = Product::query()->where('slug', $request->slug)->where('is_enabled', true)->first();
//        if (!$product) return $this->responseError();
//        $crops = $product->nutrition_programs()->where('is_enabled', true)->paginate($request->limit ?? 2);
//        $crops = [
//            'data' => CropsCollection::make($crops->items())->country($this->country)->language($this->language)->full(false),
//            'next' => $request->page < $crops->lastPage(),
//        ];
//        return $this->responseSuccess('success', $crops);
//    }
//    public function productTrialResults(Request $request): JsonResponse
//    {
//        $product = Product::query()->where('slug', $request->slug)->where('is_enabled', true)->first();
//        if (!$product) return $this->responseError();
//        $crops = $product->trial_results()
//            ->when($request->other === 'true', function ($query) {
//                $query->whereHas('countries', function ($query) {
//                    $query->where('code', '!=', $this->country);
//                });
//            })->when($request->other === 'false', function ($query) {
//                $query->whereHas('countries', function ($query) {
//                    $query->where('code', $this->country);
//                });
//            })
//            ->where('is_enabled', true)->paginate($request->limit ?? 2);
//        $crops = [
//            'data' => CropsCollection::make($crops->items())->country($this->country)->language($this->language)->full(false),
//            'next' => $request->page < $crops->lastPage(),
//        ];
//        return $this->responseSuccess('success', $crops);
//    }

    /**
     * @OA\Get(
     *  path="/posts",
     *  operationId="getPosts",
     *  tags={"Posts"},
     *  summary="Posts list",
     *  description="Posts list",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="page",in="query",description="Page number", required=false, example="1", @OA\Schema(type="integer")),
     *  @OA\Parameter(name="limit",in="query",description="Limit items", required=false, example="4", @OA\Schema(type="integer")),
     *  @OA\Parameter(name="tag",in="query",description="Type posts", required=false, example="Article", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/PostResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function getPosts(Request $request): array
    {
        $posts = Post::query()
            ->when($request->tag, function ($query) use ($request) {
                $query->where('type', $request->tag);
            })
            ->where('is_enabled', true)->paginate($request->limit ?? 2);

        return [
            'data' => PostCollection::make($posts->items())->country($this->country)->language($this->language)->full(false),
            'next' => $posts->currentPage() < $posts->lastPage(),
        ];
    }

    /**
     * @OA\Get(
     *     path="/posts/{slug}",
     *     operationId="getPostPage",
     *     tags={"Posts"},
     *     summary="Post page",
     *     description="Post",
     *      @OA\Parameter(name="slug",in="path",description="Post slug", required=true, example="challenges_of_the_21st_century", @OA\Schema(type="string")),
     *      @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *      @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *      @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *          @OA\Property(property="status", type="string", example="success"),
     *          @OA\Property(property="data", type="object", ref="#/components/schemas/PostResource"),
     *      ),),
     *      @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function post(Request $request): JsonResponse
    {
        $post = Post::query()->where('slug', $request->slug)->first();
        if (!$post) return $this->responseError();
        return $this->responseSuccess('success', PostResource::make($post, $this->language, $this->country, true));
    }

    /**
     * @OA\Get(
     *  path="/vacancies",
     *  operationId="getVacancies",
     *  tags={"Career"},
     *  summary="Vacancies list",
     *  description="Vacancies list",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="page",in="query",description="Page number", required=false, example="1", @OA\Schema(type="integer")),
     *  @OA\Parameter(name="limit",in="query",description="Limit items", required=false, example="4", @OA\Schema(type="integer")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/VacancyResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function vacancies(Request $request): array
    {
        $vacancies = Vacancy::query()->where('is_enabled', true)->paginate($request->limit ?? 2);

        return [
            'data' => VacancyCollection::make($vacancies->items())->country($this->country)->language($this->language)->full(false),
            'next' => $vacancies->currentPage() < $vacancies->lastPage(),
        ];
    }

    /**
     * @OA\Get(
     *  path="/employees",
     *  operationId="getEmployees",
     *  tags={"Employees"},
     *  summary="Employees list",
     *  description="Employees list",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="page",in="query",description="Page number", required=false, example="1", @OA\Schema(type="integer")),
     *  @OA\Parameter(name="limit",in="query",description="Limit items", required=false, example="4", @OA\Schema(type="integer")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/EmployeeResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function employees(Request $request): array
    {
        $page = Page::query()->where('name', 'About us')->first();
        $employees = $page->employees()->orderBy('sort_order')->paginate($request->limit ?? 2);

        return [
            'data' => EmployeeCollection::make($employees->items())->country($this->country)->language($this->language),
            'next' => $employees->currentPage() < $employees->lastPage(),
        ];
    }

    /**
     * @OA\Get(
     *  path="/catalogs",
     *  operationId="getCatalogs",
     *  tags={"Catalogs"},
     *  summary="Catalogs list",
     *  description="Catalogs list",
     *  @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *  @OA\Parameter(name="product",in="query",description="Procut slug", required=false, example="wuxal", @OA\Schema(type="string")),
     *  @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *      @OA\Property(property="status", type="string", example="success"),
     *      @OA\Property(property="data", type="object", ref="#/components/schemas/CatalogResource"),
     *  ),),
     *  @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function catalogs(Request $request)
    {
        $catalogs = Catalog::query()
            ->when($request->product, function ($query) use ($request) {
                $query->whereHas('products', function ($query) use ($request) {
                    $query->where('slug', $request->product);
                });
            })
            ->get();

        return CatalogCollection::make($catalogs)->country($this->country)->language($this->language);
    }

    /**
     * @OA\Get(
     *     path="/vacancies/{slug}",
     *     operationId="getVacancyPage",
     *     tags={"Career"},
     *     summary="Vacancy page",
     *     description="Vacancy",
     *      @OA\Parameter(name="slug",in="path",description="Vacancy slug", required=true, example="chief_accountant", @OA\Schema(type="string")),
     *      @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *      @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *      @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *          @OA\Property(property="status", type="string", example="success"),
     *          @OA\Property(property="data", type="object", ref="#/components/schemas/VacancyResource"),
     *      ),),
     *      @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function vacancy(Request $request): JsonResponse
    {
        $vacancy = Vacancy::query()->where('slug', $request->slug)->first();
        if (!$vacancy) return $this->responseError();
        return $this->responseSuccess('success', VacancyResource::make($vacancy, $this->language, $this->country, true));
    }

    /**
     * @OA\Get(
     *     path="/countries",
     *     operationId="getCountries",
     *     tags={"Countries"},
     *     summary="Countries list",
     *     description="Countries",
     *      @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *          @OA\Property(property="status", type="string", example="success"),
     *          @OA\Property(property="data", type="object", ref="#/components/schemas/CountryListResource"),
     *      ),),
     *      @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function countries(Request $request): CountryListCollection
    {
        $countries = Country::query()->where('is_enabled', true)->get();

        return CountryListCollection::make($countries);
    }
    /**
     * @OA\Get(
     *     path="/languages",
     *     operationId="getLanguages",
     *     tags={"Languages"},
     *     summary="Languages list",
     *     description="Languages",
     *      @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *          @OA\Property(property="status", type="string", example="success"),
     *          @OA\Property(property="data", type="object", ref="#/components/schemas/LanguageResource"),
     *      ),),
     *      @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function languages(Request $request): CountryListCollection
    {
        $languages = Language::query()->where('is_enabled', true)->get();

        return CountryListCollection::make($languages);
    }

    /**
     * @OA\Get(
     *     path="/crops",
     *     operationId="getCrops",
     *     tags={"Crops"},
     *     summary="Crops list",
     *     description="Crops",
     *      @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *      @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *      @OA\Parameter(name="slug",in="query",description="Crop slug", required=false, example="cereals", @OA\Schema(type="string")),
     *      @OA\Parameter(name="type",in="query",description="Type result", required=false, example="trials or nutrition", @OA\Schema(type="string")),
     *      @OA\Parameter(name="product",in="query",description="Product slug", required=false, example="test_slug", @OA\Schema(type="string")),
     *      @OA\Parameter(name="trials_country",in="query",description="Trial in countries", required=false, example="uk", @OA\Schema(type="string")),
     *      @OA\Parameter(name="all",in="query",description="All items", required=false, example="true", @OA\Schema(type="bool")),
     *      @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *          @OA\Property(property="status", type="string", example="success"),
     *          @OA\Property(property="data", type="object", ref="#/components/schemas/CropsResource"),
     *      ),),
     *      @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function getCrops(Request $request)
    {
        $crops = Crop::query()
            ->when($request->product, function ($query) use ($request) {
                if ($request->type === 'nutrition') {
                    $query->whereHas('nutrition_products', function ($query) use ($request) {
                        $query->where('slug', $request->product);
                    });
                } elseif ($request->type === 'trials') {
                    $query->whereHas('trial_products', function ($query) use ($request) {
                        $query->where('slug', $request->product);
                    });
                }
            })
            ->when($request->slug, function ($query) use ($request) {
                $query->where('slug', $request->slug);
            })
            ->when($request->trials_country, function ($query) use ($request) {
                $query->whereHas('countries', function ($query) use ($request) {
                    $query->where('code', $request->trials_country);
                });
            })
            ->where('is_enabled', true);

        if ($request->all && $request->all === 'true') {
            $crops = $crops->get();
            return CropsCollection::make($crops)->country($this->country)->language($this->language)->type($request->type)->full(false);
        } else {
            $crops = $crops->paginate($request->limit ?? 10);
            return [
                'data' => CropsCollection::make($crops->items())->country($this->country)->language($this->language)->type($request->type)->full(false),
                'next' => $crops->currentPage() < $crops->lastPage(),
            ];
        }
    }


    /**
     * @OA\Get(
     *     path="/crops/{slug}",
     *     operationId="getCrop",
     *     tags={"Crops"},
     *     summary="Crops list",
     *     description="Crops",
     *      @OA\Parameter(name="slug",in="path",description="Vacancy slug", required=true, example="cereals", @OA\Schema(type="string")),
     *      @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *      @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *      @OA\Parameter(name="type",in="query",description="Type result", required=false, example="trials or nutrition", @OA\Schema(type="string")),
     *      @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *          @OA\Property(property="status", type="string", example="success"),
     *          @OA\Property(property="data", type="object", ref="#/components/schemas/CropsResource"),
     *      ),),
     *      @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function getCrop(Request $request)
    {
        $crop = Crop::query()->where('slug', $request->slug)->where('is_enabled', true)->first();
        if (!$crop) return $this->responseError();
        if (!in_array($request->type, ['nutrition', 'trials'])) return $this->responseError();
        return $this->responseSuccess('success', CropsResource::make($crop, $this->language, $this->country, true, $request->type));
    }

    /**
     * @OA\Get(
     *     path="/crops/{slug}/flyers",
     *     operationId="getCropFlyers",
     *     tags={"Crops"},
     *     summary="Crops Flyers list",
     *     description="Flyers",
     *      @OA\Parameter(name="slug",in="path",description="Vacancy slug", required=true, example="cereals", @OA\Schema(type="string")),
     *      @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *      @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *      @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *          @OA\Property(property="status", type="string", example="success"),
     *          @OA\Property(property="data", type="object", ref="#/components/schemas/FlyerResource"),
     *      ),),
     *      @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function getCropFlyers(Request $request)
    {
        $crop = Crop::query()->where('slug', $request->slug)->where('is_enabled', true)->first();
        if (!$crop) return $this->responseError();
        $product = Product::query()->where('slug', $request->product)->first();
        if ($product) {
            $flyers = $crop->flyers()->wherePivot('product_id', $product->id);
        } else {
            $flyers = $crop->flyers();
        }
        if ($request->trials_country) {
            $flyers = $flyers->whereHas('countries', function ($query) use ($request) {
                $query->where('code', $request->trials_country);
            });
        }
        $flyers = $flyers->where('is_enabled', true)
            ->orderByPivot('id')->paginate($request->limit ?? 6);

        return [
            'data' => FlyerCollection::make($flyers)->language($this->language)->country($this->country),
            'next' => $flyers->currentPage() < $flyers->lastPage(),
        ];
//        return $this->responseSuccess(
//            'success',
//            $crop->flyers ? FlyerCollection::make($crop->flyers()->where('is_enabled', true)->paginate($request->limit ?? 2))->language($this->language)->country($this->country) : null
//        );
    }

    /**
     * @OA\Get(
     *     path="/search",
     *     operationId="search",
     *     tags={"Search"},
     *     summary="Search",
     *     description="Search",
     *      @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *      @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *      @OA\Parameter(name="search",in="query",description="Type result", required=false, example="Wuxal", @OA\Schema(type="string")),
     *      @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *          @OA\Property(property="status", type="string", example="success"),
     *          @OA\Property(property="products", type="array",
     *               @OA\Items(type="object",
     *                   @OA\Property(property="slug", type="string", example="wuxal"),
     *                   @OA\Property(property="type", type="string", example="product"),
     *                   @OA\Property(property="preview_title", type="string", example="Wuxal"),
     *                   @OA\Property(property="preview_image", type="string", example="https://uniferx-backend.test/storage/products/image.png"),
     *                   @OA\Property(property="logo", type="string", example="https://uniferx-backend.test/storage/products/logo.png"),
     *                   @OA\Property(property="preview_description", type="string", example="Wuxal® — is an effective suspension for foliar treatment of plants and seed treatment, as well as a set of innovative solutions that allow you to achieve high efficiency."),
     *                   @OA\Property(property="preview_button_text", type="string", example="View product"),
     *          ),),
     *          @OA\Property(property="cropsNutrition", type="object", ref="#/components/schemas/CropsResource"),
     *          @OA\Property(property="cropsTrials", type="object", ref="#/components/schemas/CropsResource"),
     *          @OA\Property(property="posts", type="object", ref="#/components/schemas/PostResource"),
     *          @OA\Property(property="catalogs", type="object", ref="#/components/schemas/CatalogResource"),
     *          @OA\Property(property="vacancies", type="object", ref="#/components/schemas/VacancyResource"),
     *          @OA\Property(property="flyers", type="object", ref="#/components/schemas/FlyerResource"),
     *      ),),
     *      @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function search(Request $request)
    {
        $products = Product::query()->where('is_enabled', true)
            ->where('title', 'like', "%$request->search%")
            ->get()->shuffle()->take(4);
        $cropsNutrition = Crop::query()->where('is_enabled', true)
            ->has('nutrition_products')
            ->where('title', 'like', "%$request->search%")
            ->get()->shuffle()->take(4);
        $cropsTrials = Crop::query()->where('is_enabled', true)
            ->has('trial_products')
            ->where('title', 'like', "%$request->search%")
            ->get()->shuffle()->take(4);
        $posts = Post::query()->where('is_enabled', true)
            ->where('title', 'like', "%$request->search%")
            ->get()->shuffle()->take(4);
        $catalogs = Catalog::query()->where('is_enabled', true)
            ->where('title', 'like', "%$request->search%")
            ->get()->shuffle()->take(4);
        $vacancies = Vacancy::query()->where('is_enabled', true)
            ->where('title', 'like', "%$request->search%")
            ->get()->shuffle()->take(4);
        $flyers = Flyer::query()->where('is_enabled', true)
            ->where('title', 'like', "%$request->search%")
            ->get()->shuffle()->take(4);

        return $this->responseSuccess('success', [
            'products' => ProductCollection::make($products)->country($this->country)->language($this->language)->full(false),
            'cropsNutrition' => CropsCollection::make($cropsNutrition)->country($this->country)->language($this->language)->type(null)->full(false),
            'cropsTrials' => CropsCollection::make($cropsTrials)->country($this->country)->language($this->language)->type(null)->full(false),
            'posts' => PostCollection::make($posts)->country($this->country)->language($this->language)->full(false),
            'catalogs' => CatalogCollection::make($catalogs)->country($this->country)->language($this->language),
            'vacancies' => VacancyCollection::make($vacancies)->country($this->country)->language($this->language)->full(false),
            'flyers' => FlyerCollection::make($flyers)->country($this->country)->language($this->language),
        ]);
    }

    /**
     * @OA\Get(
     *     path="/search/products",
     *     operationId="searchProducts",
     *     tags={"Search"},
     *     summary="Search Products",
     *     description="Search Products",
     *      @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *      @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *      @OA\Parameter(name="search",in="query",description="Type result", required=false, example="Wuxal", @OA\Schema(type="string")),
     *      @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *          @OA\Property(property="status", type="string", example="success"),
     *          @OA\Property(property="data", type="array",
     *               @OA\Items(type="object",
     *                   @OA\Property(property="slug", type="string", example="wuxal"),
     *                   @OA\Property(property="type", type="string", example="product"),
     *                   @OA\Property(property="preview_title", type="string", example="Wuxal"),
     *                   @OA\Property(property="preview_image", type="string", example="https://uniferx-backend.test/storage/products/image.png"),
     *                   @OA\Property(property="logo", type="string", example="https://uniferx-backend.test/storage/products/logo.png"),
     *                   @OA\Property(property="preview_description", type="string", example="Wuxal® — is an effective suspension for foliar treatment of plants and seed treatment, as well as a set of innovative solutions that allow you to achieve high efficiency."),
     *                   @OA\Property(property="preview_button_text", type="string", example="View product"),
     *          ),),
     *      ),),
     *      @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function searchProducts(Request $request)
    {
        $products = Product::query()->where('is_enabled', true)
            ->where('title', 'like', "%$request->search%")
            ->get()->shuffle()->take(4);

        return $this->responseSuccess('success', ProductCollection::make($products)->country($this->country)->language($this->language)->full(false));
    }



    /**
     * @OA\Get(
     *     path="/search/crops",
     *     operationId="searchCrops",
     *     tags={"Search"},
     *     summary="Search Crops",
     *     description="Search Crops",
     *      @OA\Parameter(name="language",in="query",description="Page language", required=true, example="en", @OA\Schema(type="string")),
     *      @OA\Parameter(name="country",in="query",description="Page country", required=true, example="en", @OA\Schema(type="string")),
     *      @OA\Parameter(name="search",in="query",description="Type result", required=false, example="Wuxal", @OA\Schema(type="string")),
     *       @OA\Parameter(name="type",in="query",description="Type result", required=false, example="trials or nutrition", @OA\Schema(type="string")),
     *      @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *          @OA\Property(property="status", type="string", example="success"),
     *          @OA\Property(property="data", type="object", ref="#/components/schemas/CropsResource"),
     *      ),),
     *      @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function searchCrops(Request $request)
    {
        $crops = Crop::query()->where('is_enabled', true)
            ->has($request->type = 'nutrition' ? 'nutrition_products' : 'trial_products')
            ->where('title', 'like', "%$request->search%")
            ->get()->shuffle()->take(4);

        return $this->responseSuccess('success', CropsCollection::make($crops)->country($this->country)->language($this->language)->type(null)->full(false));
    }

    /**
     * @OA\Post(
     *     path="/form",
     *     operationId="sendForm",
     *     tags={"Form"},
     *     summary="Send Form",
     *     description="Send Form",
     *      @OA\Parameter(name="email",in="query",description="Email", required=true, example="user@gmail.com", @OA\Schema(type="string")),
     *      @OA\Parameter(name="name",in="query",description="Name", required=true, example="User", @OA\Schema(type="string")),
     *      @OA\Parameter(name="phone",in="query",description="Phone", required=false, example="+380999999999", @OA\Schema(type="string")),
     *      @OA\Parameter(name="organization",in="query",description="Organization", required=false, example="Goodface", @OA\Schema(type="string")),
     *      @OA\Parameter(name="category",in="query",description="Category", required=false, example="Partner", @OA\Schema(type="string")),
     *      @OA\Parameter(name="message",in="query",description="Message", required=false, example="Text message", @OA\Schema(type="string")),
     *      @OA\Parameter(name="from_page",in="query",description="The page from which the request was made", required=false, example="Homepage", @OA\Schema(type="string")),
     *      @OA\Parameter(name="file",in="query",description="File", required=false, example="file.pdf", @OA\Schema(type="file")),
     *      @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *          @OA\Property(property="status", type="string", example="success"),
     *           @OA\Property(property="data", type="object", example="message sent"),
     *      ),),
     *      @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function form(SendFormRequest $request)
    {
        try {
            if ($request->file()) {
                $fileName = $request->file('file')->hashName();
                Storage::disk('public')->put("forms", $request->file('file'));
                $file = Storage::url("forms/$fileName");
            }
            Mail::to('Info@uniferx.com')->send(new SendForm($request->all(), $file ?? null, $fileName ?? null));
            return $this->responseSuccess('success', 'message sent');
        } catch (\Exception $exception) {
            return $this->responseError('error', 'sending error');
        }

    }

    /**
     * @OA\Post(
     *     path="/subscribe",
     *     operationId="Subscribe",
     *     tags={"Form"},
     *     summary="Subscribe Form",
     *     description="Subscribe Form",
     *      @OA\Parameter(name="email",in="query",description="Email", required=true, example="user@gmail.com", @OA\Schema(type="string")),
     *      @OA\Response(response=200,description="Successful operation", @OA\JsonContent(
     *          @OA\Property(property="status", type="string", example="success"),
     *          @OA\Property(property="data", type="object", example="message sent"),
     *      ),),
     *      @OA\Response(response=401,description="Unauthenticated",),
     * )
     */
    public function subscribe(SendFormRequest $request)
    {
        try {
            Mail::to($request->email)->send(new SubscribeNews($request->email));
            return $this->responseSuccess('success', 'message sent');
        } catch (\Exception $exception) {
            return $this->responseError('error', 'sending error');
        }
    }
}