<data>
	<organization>
		<name>${organizationData.name}</name>
		<address>${organizationData.mainContact.address}</address>
	</organization>
	<created>${now?string["dd.MM.yyyy"]}</created>
    <#list participantsData as participant>
        <@printParticipant participant />
    </#list>
</data>

<#macro printParticipant participant>
	<#local contacts = participantContacts?api.get(participant.id)>
	<#local infos = participantInfos?api.get(participant.id)>
	<#local assets = participantAssets?api.get(participant.id)>
	<#if assets?has_content>
		<#if ParticipantFunctions.getAssetByFunction(assets, 'Fena')??>
	        <#local fena = ParticipantFunctions.getAssetByFunction(assets, 'Fena')>
	    </#if>
		<#if ParticipantFunctions.getAssetByFunction(assets, 'Pes')??>
            <#local pes = ParticipantFunctions.getAssetByFunction(assets, 'Pes')>
        </#if>
	</#if>
	<participant>
		<formNumber></formNumber>
		<breed><#if fena??>${ParticipantFunctions.getAssetAttributeValue(fena.renderedAttributes, 'Varieta')}</#if></breed>
		<breedingStation>
            <#local chsContact = ParticipantFunctions.getContactByType(contacts, 'Chovatelská stanice')>
			<name>${chsContact.name}</name>
			<breeder>${participant.name}</breeder>
			<address>${chsContact.address}</address>
		</breedingStation>
		<female>
			<name><#if fena??>${fena.name!""}</#if></name>
			<number><#if fena??>${fena.number!""}</#if></number>
			<#if fena??>
			    <#local femaleMembers = assetMembers?api.get(fena.id)![]>

				<#if ParticipantFunctions.getAssetMemberByType(femaleMembers, 'Majitel')??>
					<#local femaleMemberByType = ParticipantFunctions.getAssetMemberByType(femaleMembers, 'Majitel')>
					<#if femaleMemberByType?has_content>
	                    <#local femaleOwnerContact = ParticipantFunctions.getContactByType(femaleMemberByType.contacts, 'Kontaktní adresa')>
					</#if>
				</#if>
			</#if>
			<owner>
				<name><#if femaleMemberByType??>${femaleMemberByType.name!""}</#if></name>
				<address><#if femaleOwnerContact??>${femaleOwnerContact.address}</#if></address>
			</owner>
		</female>
		<male>
			<name><#if pes??>${pes.name!""}</#if></name>
			<number><#if pes??>${pes.number!""}</#if></number>
            <#if pes??>
                <#local maleMembers = assetMembers?api.get(pes.id)![]>
	            <#if ParticipantFunctions.getAssetMemberByType(maleMembers, 'Majitel')??>
	                <#local maleMemberByType = ParticipantFunctions.getAssetMemberByType(maleMembers, 'Majitel')>
	                <#if maleMemberByType?has_content>
	                    <#local maleOwnerContact = ParticipantFunctions.getContactByType(maleMemberByType.contacts, 'Kontaktní adresa')>
	                </#if>
                </#if>
            </#if>
			<owner>
				<name><#if maleMemberByType??>${maleMemberByType.name!""}</#if></name>
				<address><#if maleOwnerContact??>${maleOwnerContact.address}</#if></address>
			</owner>
		</male>
	</participant>
</#macro>