from odoo import fields, models


class MailQuickTemplateFavorite(models.Model):
    _name = 'mail.quick.template.favorite'
    _description = 'Chatter Quick Reply Template Favorite'
    _rec_name = 'template_id'

    user_id = fields.Many2one(
        'res.users', string='User', required=True, ondelete='cascade',
        default=lambda self: self.env.user, index=True,
    )
    template_id = fields.Many2one(
        'mail.quick.template', string='Template', required=True,
        ondelete='cascade', index=True,
    )
    created_date = fields.Datetime(
        string='Favorited On', default=fields.Datetime.now, readonly=True,
    )

    _user_template_uniq = models.Constraint(
        'UNIQUE(user_id, template_id)',
        'A user can only favorite a template once.',
    )
