/home/bdqbpbxa/api-uniferx.goodface.com.ua/app/Http/Resources/Pages/About/AboutResource.php
<?php

namespace App\Http\Resources\Pages\About;

use App\Helpers\ResourceHelper;
use App\Http\Resources\Pages\About\Employees\EmployeeCollection;
use App\Http\Resources\Pages\Cards\MissionCardCollection;
use App\Http\Resources\Pages\TermsConditions\BlockCollection;
use App\Models\Post;
use App\Models\Product;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * @OA\Schema(title="AboutResource", description="About resource",
 *     @OA\Xml(name="AboutResource")
 * )
 */
class AboutResource extends JsonResource
{
    /**
     * @OA\Property(property="fs_title", type="string", example=""),
     * @OA\Property(property="fs_background", type="string", example=""),
     * @OA\Property(property="fs_description", type="string", example=""),
     * @OA\Property(property="about_tag", type="string", example=""),
     * @OA\Property(property="about_title", type="string", example=""),
     * @OA\Property(property="about_text", type="string", example=""),
     * @OA\Property(property="about_card_text", type="string", example=""),
     * @OA\Property(property="about_card_image", type="string", example=""),
     * @OA\Property(property="mission_background_image", type="string", example=""),
     * @OA\Property(property="mission_cards", type="array",
     *       @OA\Items(type="object",ref="#/components/schemas/MissionCardResource"),
     *  ),
     * @OA\Property(property="employees", type="array",
     *       @OA\Items(type="object",ref="#/components/schemas/EmployeeResource"),
     *  ),
     * @OA\Property(property="team_title", type="string", example=""),
     * @OA\Property(property="team_card_title", type="string", example=""),
     * @OA\Property(property="team_card_text", type="string", example=""),
     * @OA\Property(property="team_card_button", type="string", example=""),
     * @OA\Property(property="team_show_more", type="string", example=""),
     * @OA\Property(property="history_title", type="string", example=""),
     * @OA\Property(property="histories_cards", type="array",
     *      @OA\Items(type="object",ref="#/components/schemas/MissionCardResource"),
     * ),
     * @OA\Property(property="histories_image", type="string", example=""),
     * @OA\Property(property="cta_tag", type="string", example=""),
     * @OA\Property(property="cta_title", type="string", example=""),
     * @OA\Property(property="cta_image", type="string", example=""),
     * @OA\Property(property="cta_field_name_title", type="string", example=""),
     * @OA\Property(property="cta_field_name_placeholder", type="string", example=""),
     * @OA\Property(property="cta_field_email_title", type="string", example=""),
     * @OA\Property(property="cta_field_email_placeholder", type="string", example=""),
     * @OA\Property(property="cta_field_phone_title", type="string", example=""),
     * @OA\Property(property="cta_field_phone_placeholder", type="string", example=""),
     * @OA\Property(property="cta_field_organization_title", type="string", example=""),
     * @OA\Property(property="cta_field_organization_placeholder", type="string", example=""),
     * @OA\Property(property="cta_field_sender_title", type="string", example=""),
     * @OA\Property(property="cta_field_sender_options", type="string", example=""),
     * @OA\Property(property="cta_field_message_title", type="string", example=""),
     * @OA\Property(property="cta_field_message_placeholder", type="string", example=""),
     * @OA\Property(property="cta_policy_text", type="string", example=""),
     * @OA\Property(property="cta_submit_button", type="string", example=""),
     */
    public string|null $name;
    public string|null $language;
    public string|null $country;
    public array|null $data;
    public object|null $employees;

    public function __construct($resource, $language, $country)
    {
        parent::__construct($resource);
        $this->name = $resource->name;
        $this->language = $language;
        $this->country = $country;
        $this->data = $resource->data;
        $this->employees = $resource->employees;
    }

    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
//        dd($this->data['mission_cards']);
        return [
            'fs_title' => ResourceHelper::getValue($this->data['fs_title'] ?? null, $this->country, $this->language),
            'fs_background' => ResourceHelper::getImage($this->data['fs_background'] ?? null),
            'fs_description' => ResourceHelper::getValue($this->data['fs_description'] ?? null, $this->country, $this->language),
            'about_tag' => ResourceHelper::getValue($this->data['about_tag'] ?? null, $this->country, $this->language),
            'about_title' => ResourceHelper::getValue($this->data['about_title'] ?? null, $this->country, $this->language),
            'about_text' => ResourceHelper::getValue($this->data['about_text'] ?? null, $this->country, $this->language),
            'about_card_text' => ResourceHelper::getValue($this->data['about_card_text'] ?? null, $this->country, $this->language),
            'about_card_image' => ResourceHelper::getImage($this->data['about_card_image'] ?? null),
            'mission_title' => ResourceHelper::getValue($this->data['mission_title'] ?? null, $this->country, $this->language),
            'mission_background_image' => ResourceHelper::getImage($this->data['mission_background_image'] ?? null),
            'mission_cards' => isset($this->data['mission_cards']) ? MissionCardCollection::make( is_array($this->data['mission_cards']) ? $this->data['mission_cards'] : json_decode($this->data['mission_cards']))->country($this->country)->language($this->language) : null,
//            'employees' => EmployeeCollection::make($this->employees)->language($this->language)->country($this->country),
            'team_tag' => ResourceHelper::getValue($this->data['team_tag'] ?? null, $this->country, $this->language),
            'team_title' => ResourceHelper::getValue($this->data['team_title'] ?? null, $this->country, $this->language),
            'team_card_title' => ResourceHelper::getValue($this->data['team_card_title'] ?? null, $this->country, $this->language),
            'team_card_text' => ResourceHelper::getValue($this->data['team_card_text'] ?? null, $this->country, $this->language),
            'team_card_button' => ResourceHelper::getValue($this->data['team_card_button'] ?? null, $this->country, $this->language),
            'team_show_more' => ResourceHelper::getValue($this->data['team_show_more'] ?? null, $this->country, $this->language),
            'history_title' => ResourceHelper::getValue($this->data['history_title'] ?? null, $this->country, $this->language),
            'histories_cards' => isset($this->data['histories_cards']) ? MissionCardCollection::make( is_array($this->data['histories_cards']) ? $this->data['histories_cards'] : json_decode($this->data['histories_cards']))->country($this->country)->language($this->language) : null,
            'histories_image' => ResourceHelper::getImage($this->data['histories_image'] ?? null),
//            'cta_tag' => ResourceHelper::getValue($this->data['cta_tag'] ?? null, $this->country, $this->language),
//            'cta_title' => ResourceHelper::getValue($this->data['cta_title'] ?? null, $this->country, $this->language),
//            'cta_image' => ResourceHelper::getValue($this->data['cta_image'] ?? null, $this->country, $this->language),
//            'cta_field_name_title' => ResourceHelper::getValue($this->data['cta_field_name_title'] ?? null, $this->country, $this->language),
//            'cta_field_name_placeholder' => ResourceHelper::getValue($this->data['cta_field_name_placeholder'] ?? null, $this->country, $this->language),
//            'cta_field_email_title' => ResourceHelper::getValue($this->data['cta_field_email_title'] ?? null, $this->country, $this->language),
//            'cta_field_email_placeholder' => ResourceHelper::getValue($this->data['cta_field_email_placeholder'] ?? null, $this->country, $this->language),
//            'cta_field_phone_title' => ResourceHelper::getValue($this->data['cta_field_phone_title'] ?? null, $this->country, $this->language),
//            'cta_field_phone_placeholder' => ResourceHelper::getValue($this->data['cta_field_phone_placeholder'] ?? null, $this->country, $this->language),
//            'cta_field_organization_title' => ResourceHelper::getValue($this->data['cta_field_organization_title'] ?? null, $this->country, $this->language),
//            'cta_field_organization_placeholder' => ResourceHelper::getValue($this->data['cta_field_organization_placeholder'] ?? null, $this->country, $this->language),
//            'cta_field_sender_title' => ResourceHelper::getValue($this->data['cta_field_sender_title'] ?? null, $this->country, $this->language),
//            'cta_field_sender_options' => ResourceHelper::getValue($this->data['cta_field_sender_options'] ?? null, $this->country, $this->language),
//            'cta_field_message_title' => ResourceHelper::getValue($this->data['cta_field_message_title'] ?? null, $this->country, $this->language),
//            'cta_field_message_placeholder' => ResourceHelper::getValue($this->data['cta_field_message_placeholder'] ?? null, $this->country, $this->language),
//            'cta_policy_text' => ResourceHelper::getValue($this->data['cta_policy_text'] ?? null, $this->country, $this->language),
//            'cta_submit_button' => ResourceHelper::getValue($this->data['cta_submit_button'] ?? null, $this->country, $this->language),
        ];
    }

}