<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity repository-class="App\Entity\FicheEspaceRepository" name="App\Entity\FicheEspace">
    <id name="id" type="integer" column="id">
      <generator strategy="AUTO"/>
    </id>
    <field name="persistant" type="boolean" column="persistant" nullable="true"/>
    <field name="duree" type="integer" column="duree" nullable="true"/>
    <field name="dureeRestante" type="integer" column="dureeRestante" nullable="true"/>

    <field name="jours" type="simple_array" column="jours" nullable="true"/>

    <many-to-one field="fiche" target-entity="App\Entity\Fiche" inversed-by="espaces" fetch="LAZY" >
      <join-columns>
        <join-column name="fiche_id" referenced-column-name="id" nullable="false"/>
      </join-columns>
    </many-to-one>

    <many-to-one field="espace" target-entity="App\Entity\Espace" inversed-by="fiches" fetch="LAZY" >
      <join-columns>
        <join-column name="espace_id" referenced-column-name="id" nullable="false"/>
      </join-columns>
    </many-to-one>

    <many-to-many field="categories" target-entity="Intitule" inversed-by="fichesEspaces" fetch="LAZY">
      <join-table name="fiches_espaces_intitules">
        <join-columns>
          <join-column name="fiche_espace_id" referenced-column-name="id" />
        </join-columns>
        <inverse-join-columns>
          <join-column name="intitule_id" referenced-column-name="id"/>
        </inverse-join-columns>
      </join-table>
    </many-to-many>

    <one-to-one field="generatedDemande" target-entity="Demande" inversed-by="ficheEspace" fetch="LAZY">
        <cascade><cascade-persist /></cascade>
        <join-column name="generated_demande_id" referenced-column-name="id" nullable="true" on-delete="SET NULL"/>
    </one-to-one>

    <unique-constraints>
        <unique-constraint columns="espace_id,fiche_id" name="fiche_espace_unique" />
    </unique-constraints>
  </entity>
</doctrine-mapping>
