Weak hands cannot be planted, meager skills have no foundation. Shallow wisdom is futile, how can one hope for a good name?扰扰从役倦，屑屑身事微。少壮轻年月，迟暮惜光辉。
<html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><?php

namespace Hostinger\Reach\Api\Handlers;

use Hostinger\Reach\Functions;
use Hostinger\Reach\Repositories\ContactListRepository;
use Hostinger\Reach\Repositories\FormRepository;
use WP_REST_Request;
use WP_REST_Response;
use Exception;

if ( ! defined( 'ABSPATH' ) ) {
    die;
}

class FormsApiHandler extends ApiHandler {

    public const FORMS_API_HANDLER_LAST_UPDATE = 'hostinger_reach_forms_api_handler_last_update';

    private ContactListRepository $contact_list_repository;
    private FormRepository $form_repository;

    public function __construct( Functions $functions, ContactListRepository $contact_list_repository, FormRepository $form_repository ) {
        parent::__construct( $functions );
        $this->contact_list_repository = $contact_list_repository;
        $this->form_repository         = $form_repository;
    }

    public function get_contact_lists_handler(): WP_REST_Response {
        $contact_lists = $this->contact_list_repository->all();

        return $this->handle_response(
            array(
                'response' => array(
                    'code' => 200,
                ),
                'body'     => wp_json_encode( $contact_lists ),
            )
        );
    }

    public function get_forms_handler( WP_REST_Request $request ): WP_REST_Response {
        $contact_list_id = $request->get_param( 'contact_list_id' );
        $type            = $request->get_param( 'type' );
        $args            = array( 'type' => $type );
        if ( $contact_list_id ) {
            $args['contact_list_id'] = $contact_list_id;
        }
        $forms = apply_filters( 'hostinger_reach_forms', array(), $args );

        if ( ! empty( $forms ) ) {
            update_option( Functions::HOSTINGER_REACH_HAS_USER_ACTION, true );
            update_option( Functions::HOSTINGER_REACH_HAS_FORMS, true );
        } else {
            update_option( Functions::HOSTINGER_REACH_HAS_FORMS, false );
        }

        return $this->handle_response(
            array(
                'response' => array(
                    'code' => 200,
                ),
                'body'     => wp_json_encode( $forms ),
            )
        );
    }

    public function post_forms_handler( WP_REST_Request $request ): WP_REST_Response {
        $form_id   = $request->get_param( 'form_id' );
        $type      = $request->get_param( 'type' );
        $is_active = (int) $request->get_param( 'is_active' );

        try {
            $is_updated = apply_filters(
                'hostinger_reach_after_form_state_is_set',
                $this->form_repository->update(
                    array(
                        'form_id'   => $form_id,
                        'is_active' => $is_active,
                    )
                ),
                $form_id,
                $is_active,
                $type
            );
     