<?xml version="1.0" encoding="UTF-8"?>
<domain-models xmlns="http://axelor.com/xml/ns/domain-models" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://axelor.com/xml/ns/domain-models http://axelor.com/xml/ns/domain-models/domain-models_5.2.xsd">
  
  <module name="message" package="com.axelor.apps.message.db"/>
  
  <entity name="Message" lang="java">
  
  	<integer name="typeSelect" title="Type" selection="message.type.select" readonly="true" default="2" initParam="true"/>
	<string name="subject" title="Subject" initParam="true" namecolumn="true"/>
  	<string name="content" title="Content" large="true" initParam="true"/>
	<datetime name="sentDateT" title="Sent date" readonly="true"/>
 	<date name="sendScheduleDate" title="Forecasted Sent Date" />
	<string name="relatedTo1Select" title="Related to" selection="message.related.to.select"/>
    <long name="relatedTo1SelectId"/>
  	<string name="relatedTo2Select" title="Related to" selection="message.related.to.select"/>
    <long name="relatedTo2SelectId"/>
	<integer name="statusSelect" title="Status" selection="message.status.select" readonly="true" default="1" initParam="true"/>

  	<integer name="mediaTypeSelect" title="Media Type" selection="message.media.type.select" initParam="true"/>
	<string name="addressBlock" large="true" multiline="true" title="Address Block" initParam="true"/>
	
  	<!-- Email -->
  	<many-to-one name="fromEmailAddress" ref="com.axelor.apps.message.db.EmailAddress" title="From" initParam="true"/>
  	<many-to-many name="replyToEmailAddressSet" ref="com.axelor.apps.message.db.EmailAddress" title="Reply to" initParam="true" />
  	<many-to-many name="toEmailAddressSet" ref="com.axelor.apps.message.db.EmailAddress" title="To" initParam="true"/>
  	<many-to-many name="ccEmailAddressSet" ref="com.axelor.apps.message.db.EmailAddress" title="Cc" initParam="true"/>
  	<many-to-many name="bccEmailAddressSet" ref="com.axelor.apps.message.db.EmailAddress" title="Bcc" initParam="true"/>
  	<boolean name="sentByEmail" title="Sent by email" initParam="true"/>
  	<many-to-one name="mailAccount" ref="com.axelor.apps.message.db.EmailAccount" title="Mail account" initParam="true"/>
  	
  	<!--   	Intern message -->
  	<many-to-one name="senderUser" ref="com.axelor.auth.db.User" title="Sender (User)" readonly="true"/>
  	<many-to-one name="recipientUser" ref="com.axelor.auth.db.User" title="Recipient"/>
	<many-to-one name="template" ref="com.axelor.apps.message.db.Template" readonly="true"/>

	<finder-method name="findByRelatedTo"
		using="long:relatedToSelectId,String:relatedToSelect"
		filter="self.relatedTo1SelectId = :relatedToSelectId
				AND self.relatedTo1Select = :relatedToSelect
			OR self.relatedTo2SelectId = :relatedToSelectId
				AND self.relatedTo2Select = :relatedToSelect" all="true"/>

  	<extra-code><![CDATA[

		// TYPE SELECT
		public static final int TYPE_RECEIVED = 1;
		public static final int TYPE_SENT = 2; 
		
		// STATUS SELECT
		public static final int STATUS_DRAFT = 1;
		public static final int STATUS_IN_PROGRESS = 2;
		public static final int STATUS_SENT = 3; 
		public static final int STATUS_DELETED = 4; 
		
		// MEDIA TYPE SELECT
		public static final int MEDIA_TYPE_MAIL = 1;
		public static final int MEDIA_TYPE_EMAIL = 2; 
		public static final int MEDIA_TYPE_CHAT = 3; 
	
		// RELATED TO SELECT
		public static final String RELATED_TO_PARTNER = "com.axelor.apps.base.db.Partner";
		public static final String RELATED_TO_LEAD = "com.axelor.apps.crm.db.Lead";
		public static final String RELATED_TO_OPPORTUNITY = "com.axelor.apps.crm.db.Opportunity";
		public static final String RELATED_TO_PRODUCT = "com.axelor.apps.base.db.Product";
		public static final String RELATED_TO_EVENT = "com.axelor.apps.crm.db.Event";
		public static final String RELATED_TO_SALESORDER = "com.axelor.apps.sale.db.SaleOrder";
		public static final String RELATED_TO_PROJECT = "com.axelor.apps.project.db.Project";
	
	]]></extra-code>
	
	
  </entity>
  
</domain-models>
