<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data noupdate="1">

        <!-- Sync call history every 5 minutes -->
        <record id="ir_cron_sync_call_history" model="ir.cron">
            <field name="name">Fusion RingCentral: Sync Call History</field>
            <field name="model_id" ref="model_rc_call_history"/>
            <field name="state">code</field>
            <field name="code">model._cron_sync_call_history()</field>
            <field name="interval_number">5</field>
            <field name="interval_type">minutes</field>
            <field name="active">True</field>
        </record>

        <!-- Refresh OAuth tokens every 30 minutes -->
        <record id="ir_cron_refresh_tokens" model="ir.cron">
            <field name="name">Fusion RingCentral: Refresh OAuth Tokens</field>
            <field name="model_id" ref="model_rc_config"/>
            <field name="state">code</field>
            <field name="code">model._cron_refresh_tokens()</field>
            <field name="interval_number">30</field>
            <field name="interval_type">minutes</field>
            <field name="active">True</field>
        </record>

        <!-- Renew webhook subscriptions daily -->
        <record id="ir_cron_renew_webhooks" model="ir.cron">
            <field name="name">Fusion RingCentral: Renew Webhook Subscriptions</field>
            <field name="model_id" ref="model_rc_config"/>
            <field name="state">code</field>
            <field name="code">model._cron_renew_webhooks()</field>
            <field name="interval_number">1</field>
            <field name="interval_type">days</field>
            <field name="active">True</field>
        </record>

        <!-- Daily catchup: re-scan past 3 days for calls from phones/mobile -->
        <record id="ir_cron_daily_catchup_sync" model="ir.cron">
            <field name="name">Fusion RingCentral: Daily Call Catchup</field>
            <field name="model_id" ref="model_rc_call_history"/>
            <field name="state">code</field>
            <field name="code">model._cron_daily_catchup_sync()</field>
            <field name="interval_number">1</field>
            <field name="interval_type">days</field>
            <field name="active">True</field>
        </record>

        <!-- Historical import (triggered manually from UI button) -->
        <record id="cron_rc_historical_import" model="ir.cron">
            <field name="name">Fusion RingCentral: Historical Import</field>
            <field name="cron_name">Fusion RingCentral: Historical Import</field>
            <field name="model_id" ref="model_rc_config"/>
            <field name="state">code</field>
            <field name="code">model._run_historical_import()</field>
            <field name="interval_number">9999</field>
            <field name="interval_type">days</field>
            <field name="active">False</field>
        </record>

        <!-- Fetch transcripts every 15 minutes -->
        <record id="ir_cron_fetch_transcripts" model="ir.cron">
            <field name="name">Fusion RingCentral: Fetch Call Transcripts</field>
            <field name="model_id" ref="model_rc_call_history"/>
            <field name="state">code</field>
            <field name="code">model._cron_fetch_transcripts()</field>
            <field name="interval_number">15</field>
            <field name="interval_type">minutes</field>
            <field name="active">True</field>
        </record>

        <!-- Backfill voicemail audio/transcripts (triggered manually) -->
        <record id="cron_rc_backfill_vm_media" model="ir.cron">
            <field name="name">Fusion RingCentral: Backfill Voicemail Media</field>
            <field name="cron_name">Fusion RingCentral: Backfill Voicemail Media</field>
            <field name="model_id" ref="model_rc_voicemail"/>
            <field name="state">code</field>
            <field name="code">model._run_backfill_voicemail_media()</field>
            <field name="interval_number">9999</field>
            <field name="interval_type">days</field>
            <field name="active">False</field>
        </record>

        <!-- Historical voicemail import (triggered manually from UI button) -->
        <record id="cron_rc_historical_vm_import" model="ir.cron">
            <field name="name">Fusion RingCentral: Historical Voicemail Import</field>
            <field name="cron_name">Fusion RingCentral: Historical Voicemail Import</field>
            <field name="model_id" ref="model_rc_voicemail"/>
            <field name="state">code</field>
            <field name="code">model._run_historical_voicemail_import()</field>
            <field name="interval_number">9999</field>
            <field name="interval_type">days</field>
            <field name="active">False</field>
        </record>

        <!-- Sync voicemails every 5 minutes -->
        <record id="ir_cron_sync_voicemails" model="ir.cron">
            <field name="name">Fusion RingCentral: Sync Voicemails</field>
            <field name="model_id" ref="model_rc_voicemail"/>
            <field name="state">code</field>
            <field name="code">model._cron_sync_voicemails()</field>
            <field name="interval_number">5</field>
            <field name="interval_type">minutes</field>
            <field name="active">True</field>
        </record>

        <!-- Daily catchup: re-scan past 3 days for voicemails -->
        <record id="ir_cron_daily_voicemail_catchup" model="ir.cron">
            <field name="name">Fusion RingCentral: Daily Voicemail Catchup</field>
            <field name="model_id" ref="model_rc_voicemail"/>
            <field name="state">code</field>
            <field name="code">model._cron_daily_voicemail_catchup()</field>
            <field name="interval_number">1</field>
            <field name="interval_type">days</field>
            <field name="active">True</field>
        </record>

        <!-- Transcribe voicemails every 15 minutes -->
        <record id="ir_cron_transcribe_voicemails" model="ir.cron">
            <field name="name">Fusion RingCentral: Transcribe Voicemails</field>
            <field name="model_id" ref="model_rc_voicemail"/>
            <field name="state">code</field>
            <field name="code">model._cron_transcribe_voicemails()</field>
            <field name="interval_number">15</field>
            <field name="interval_type">minutes</field>
            <field name="active">True</field>
        </record>

        <!-- Historical fax import (triggered manually from UI button) -->
        <record id="cron_rc_historical_fax_import" model="ir.cron">
            <field name="name">Fusion Connect: Historical Fax Import</field>
            <field name="cron_name">Fusion Connect: Historical Fax Import</field>
            <field name="model_id" ref="model_fusion_fax"/>
            <field name="state">code</field>
            <field name="code">model._run_historical_fax_import()</field>
            <field name="interval_number">9999</field>
            <field name="interval_type">days</field>
            <field name="active">False</field>
        </record>

    </data>
</odoo>
