<?xml version="1.0"?>
<!-- Comunas de Chile con cobertura de Chilexpress, con su región (la de Chilexpress y la de Magento).
     Datos de shell/Yeboyebo/regiones_chilexpress.php -->
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="yeboyebo_chilexpress_coverage_area" resource="default" engine="innodb" comment="Chilexpress: comunas con cobertura">
        <column xsi:type="int" name="id" unsigned="true" nullable="false" identity="true"/>
        <column xsi:type="varchar" name="county_code" length="10" nullable="false" comment="countyCode de Chilexpress"/>
        <column xsi:type="varchar" name="coverage_name" length="255" nullable="false" comment="coverageName de Chilexpress, capitalizado"/>
        <column xsi:type="varchar" name="region_code" length="10" nullable="false" comment="regionId de Chilexpress (R1, RM...)"/>
        <column xsi:type="varchar" name="region_name" length="255" nullable="false" comment="regionName de Chilexpress"/>
        <column xsi:type="int" name="region_id_magento" unsigned="true" nullable="true" comment="directory_country_region.region_id"/>
        <column xsi:type="varchar" name="code_magento" length="32" nullable="true" comment="directory_country_region.code (CL-XX)"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="id"/>
        </constraint>
        <constraint xsi:type="unique" referenceId="YEBOYEBO_CHILEXPRESS_COVERAGE_AREA_REGION_CODE_COUNTY_CODE">
            <column name="region_code"/>
            <column name="county_code"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="YEBOYEBO_CHILEXPRESS_COVERAGE_AREA_REGION_ID_MAGENTO_DIR_COUNTRY_REGION_REGION_ID"
                    table="yeboyebo_chilexpress_coverage_area" column="region_id_magento"
                    referenceTable="directory_country_region" referenceColumn="region_id" onDelete="SET NULL"/>
        <index referenceId="YEBOYEBO_CHILEXPRESS_COVERAGE_AREA_REGION_ID_MAGENTO" indexType="btree">
            <column name="region_id_magento"/>
        </index>
    </table>
</schema>
