create or replace view zoho_integrate.v_in_zoho_user_account_alive as SELECT `id`, `zoho_user_account_id`, `access_token`, `expired_at`
                                                                      FROM zoho_auth.v_zoho_user_account_alive ;

create or replace view zoho_integrate.v_in_zoho_user_account as SELECT *
                                                                FROM user_account_zoho.user_account;

create or replace view zoho_integrate.v_in_location_account_user as SELECT *
                                                                FROM user_account_zoho.location_account_user;

create or replace view zoho_integrate.v_in_server_account_user as SELECT *
                                                                    FROM zoho_auth.server_account_user;

create or replace view zoho_integrate.v_in_user_account_centile as SELECT `id`, `selfcare_user_id`, `subscription_id`, `is_active`
                                                                   FROM user_account_centile.user_account ;


create or replace view zoho_integrate.v_btw_to_disintegrate as SELECT z_u_alive.zoho_user_account_id FROM `subscription`. `subscription` s INNER JOIN zoho_integrate.v_in_zoho_user_account z_u ON s.customer_id =z_u.customer_id INNER JOIN zoho_integrate.v_in_zoho_user_account_alive z_u_alive ON z_u_alive.zoho_user_account_id =z_u.id WHERE s.`status_crm` LIKE 'INTEGRATED' AND s.status ='N';


create or replace view zoho_integrate.v_btw_to_integrate as SELECT z_u_alive.zoho_user_account_id FROM `subscription`. `subscription` s INNER JOIN zoho_integrate.v_in_zoho_user_account z_u ON s.customer_id =z_u.customer_id INNER JOIN zoho_integrate.v_in_zoho_user_account_alive z_u_alive ON z_u_alive.zoho_user_account_id =z_u.id WHERE s.`status_crm` LIKE 'INIT' OR (  s.`status_crm` LIKE 'NOT_INTEGRATED' AND s.status ='Y');




#code de porc à changer JBO 25/05/23
create or replace view zoho_integrate.v_subscription as SELECT * FROM subscription.`subscription` ;