<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">

    <table name="yeboyebo_updatemonitor_update" resource="default" engine="innodb"
           comment="Yeboyebo Update Monitor detected updates">
        <column xsi:type="int" name="update_id" unsigned="true" nullable="false" identity="true" comment="Update ID"/>
        <column xsi:type="varchar" name="source" nullable="false" length="32" comment="Source: core|quality_patch|composer"/>
        <column xsi:type="varchar" name="code" nullable="false" length="255" comment="Unique package or patch code"/>
        <column xsi:type="varchar" name="title" nullable="false" length="255" comment="Display title"/>
        <column xsi:type="text" name="description" nullable="true" comment="Description"/>
        <column xsi:type="varchar" name="current_version" nullable="true" length="64" comment="Current version"/>
        <column xsi:type="varchar" name="available_version" nullable="true" length="64" comment="Available version"/>
        <column xsi:type="varchar" name="severity" nullable="false" length="16" comment="critical|security|optional"/>
        <column xsi:type="varchar" name="status" nullable="false" length="16" default="open" comment="open|dismissed|resolved"/>
        <column xsi:type="varchar" name="release_notes_url" nullable="true" length="512" comment="Release notes URL"/>
        <column xsi:type="text" name="suggested_command" nullable="true" comment="Suggested CLI command"/>
        <column xsi:type="timestamp" name="first_seen_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP"
                comment="First seen"/>
        <column xsi:type="timestamp" name="last_seen_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Last seen"/>
        <column xsi:type="timestamp" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Updated at"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="update_id"/>
        </constraint>
        <constraint xsi:type="unique" referenceId="YEBOYEBO_UPDATEMONITOR_UPDATE_SOURCE_CODE">
            <column name="source"/>
            <column name="code"/>
        </constraint>
        <index referenceId="YEBOYEBO_UPDATEMONITOR_UPDATE_SEVERITY_STATUS" indexType="btree">
            <column name="severity"/>
            <column name="status"/>
        </index>
    </table>

    <table name="yeboyebo_updatemonitor_recipient" resource="default" engine="innodb"
           comment="Yeboyebo Update Monitor notification recipients">
        <column xsi:type="int" name="recipient_id" unsigned="true" nullable="false" identity="true"
                comment="Recipient ID"/>
        <column xsi:type="int" name="admin_user_id" unsigned="true" nullable="true" comment="Admin user ID"/>
        <column xsi:type="varchar" name="email" nullable="true" length="255" comment="Override email"/>
        <column xsi:type="varchar" name="name" nullable="true" length="255" comment="Display name"/>
        <column xsi:type="smallint" name="notify_critical" unsigned="true" nullable="false" default="1"
                comment="Notify critical"/>
        <column xsi:type="smallint" name="notify_security" unsigned="true" nullable="false" default="1"
                comment="Notify security"/>
        <column xsi:type="smallint" name="notify_optional" unsigned="true" nullable="false" default="0"
                comment="Notify optional"/>
        <column xsi:type="smallint" name="channel_admin" unsigned="true" nullable="false" default="1"
                comment="Magento admin inbox"/>
        <column xsi:type="smallint" name="channel_email" unsigned="true" nullable="false" default="1"
                comment="Email channel"/>
        <column xsi:type="smallint" name="is_active" unsigned="true" nullable="false" default="1" comment="Active"/>
        <column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Created at"/>
        <column xsi:type="timestamp" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Updated at"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="recipient_id"/>
        </constraint>
        <index referenceId="YEBOYEBO_UPDATEMONITOR_RECIPIENT_ACTIVE" indexType="btree">
            <column name="is_active"/>
        </index>
    </table>

    <table name="yeboyebo_updatemonitor_notification_log" resource="default" engine="innodb"
           comment="Yeboyebo Update Monitor notification anti-spam log">
        <column xsi:type="int" name="log_id" unsigned="true" nullable="false" identity="true" comment="Log ID"/>
        <column xsi:type="int" name="update_id" unsigned="true" nullable="true" comment="Update ID"/>
        <column xsi:type="int" name="recipient_id" unsigned="true" nullable="true" comment="Recipient ID"/>
        <column xsi:type="varchar" name="channel" nullable="false" length="16" comment="admin|email"/>
        <column xsi:type="varchar" name="severity" nullable="false" length="16" comment="Severity"/>
        <column xsi:type="varchar" name="fingerprint" nullable="false" length="64"
                comment="Hash of update code+version"/>
        <column xsi:type="timestamp" name="sent_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Sent at"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="log_id"/>
        </constraint>
        <index referenceId="YEBOYEBO_UPDATEMONITOR_NOTIF_LOG_FINGERPRINT" indexType="btree">
            <column name="fingerprint"/>
            <column name="channel"/>
            <column name="recipient_id"/>
        </index>
    </table>
</schema>
