create or replace view zoho_check_connection.v_in_centile_user_account as select * from user_account_centile.user_account;

create or replace view zoho_check_connection.v_in_zoho_user_account as select * from user_account_zoho.user_account;


create or replace view zoho_check_connection.v_in_zoho_user_account_in_waiting as select * from zoho_register.v_out_zoho_user_account_in_waiting;


create or replace view zoho_check_connection.v_in_zoho_user_account_alive as select * from zoho_auth.v_zoho_user_account_alive;

create or replace view zoho_check_connection.v_in_url_enabler as select * from zoho_click_to_call.url_enabler;


CREATE OR REPLACE VIEW zoho_check_connection.v_out_zoho_check_connection AS SELECT
                                                                                vizua.id AS zoho_user_account_id,
                                                                                vizua.selfcare_user_id AS selfcare_user_id,
                                                                                vizua.is_active,
                                                                                CASE
                                                                                    WHEN vizuaiw.zoho_user_account_id IS NULL THEN 'N'
                                                                                    ELSE 'Y'
                                                                                    END AS register,
                                                                                CASE
                                                                                    WHEN vizuaa.zoho_user_account_id IS NULL THEN 'N'
                                                                                    ELSE 'Y'
                                                                                    END AS auth,
                                                                                CASE
                                                                                    WHEN vizua.is_active_clicktocall IS NULL OR vizua.is_active_clicktocall = 'N' THEN 'N'
                                                                                    ELSE 'Y'
                                                                                    END AS clicktocall,
                                                                                CASE
                                                                                    WHEN vizua.is_active_clicktocall = 'Y' AND uen.zoho_user_account_id IS NOT NULL THEN 'Y'
                                                                                    ELSE 'N'
                                                                                    END AS is_active_clicktocall
                                                                            FROM
                                                                                v_in_zoho_user_account vizua
                                                                                    LEFT JOIN
                                                                                v_in_zoho_user_account_in_waiting vizuaiw ON vizuaiw.zoho_user_account_id = vizua.id
                                                                                    LEFT JOIN
                                                                                v_in_zoho_user_account_alive vizuaa ON vizuaa.zoho_user_account_id = vizua.id
                                                                                    LEFT JOIN
                                                                                zoho_check_connection.v_in_url_enabler uen ON uen.zoho_user_account_id = vizua.id;



<!----

SELECT
    vizua.id AS zoho_user_account_id,
    vizua.selfcare_user_id AS selfcare_user_id,
    vizua.is_active ,
    CASE
        WHEN vizuaiw.zoho_user_account_id IS NULL THEN 'N'
        ELSE 'Y'
        END AS register,

    CASE
        WHEN vizuaa.zoho_user_account_id IS NULL THEN 'N'
        ELSE 'Y'
        END AS auth,
    CASE
        WHEN vizua.is_active_clicktocall IS NULL OR vizua.is_active_clicktocall = 'N' THEN 'N'
        ELSE 'Y'
        END AS clicktocall
FROM v_in_zoho_user_account vizua
         LEFT JOIN v_in_zoho_user_account_in_waiting vizuaiw ON vizuaiw.zoho_user_account_id = vizua.id
         LEFT JOIN v_in_zoho_user_account_alive vizuaa ON vizuaa.zoho_user_account_id = vizua.id;

---->