class MailContent < ActiveRecord::Base
  belongs_to :lang_site
  belongs_to :mail_type
  
  belongs_to :mail_template
  
  has_one :block, :as => :blockable
  
  after_create do
    generate_block
  
  end
  
  def generate_block
    @block = Block.new(:block_name => "general", :lang_site => self.lang_site)
    @block.blockable = self
    @block.save
  end
  
  
  def alloweds_types
    
    {
      TitleContent: "Titre",
      TextContent: "Texte",
      ImageContent: "Image",
      LinkContent:"Lien",
      BreakContent: "Séparation",
      HtmlContent: "Code HTML",
      DownloadContent: "Téléchargement",

      BlockContent: "Bloc",

      ShareContent: "Ligne partage réseaux",
    
     }
  end
  
  
  def self.find_key(lang, slug )
    
    MailContent.joins(:mail_type).where(:lang_site_id =>lang, :mail_types => { :slug => slug}).first
  end
  
end
