from odoo import fields, models
from odoo.addons.mail.tools.discuss import Store


class TierChannelTag(models.Model):
    _name = 'tier.channel.tag'
    _description = 'Tier Channel Tag'
    _rec_name = 'name'

    name = fields.Char(string='Name', required=True)
    code = fields.Char(string='Code', required=True)
    active = fields.Boolean(string='Active', default=True)
    description = fields.Text(string='Description')
    is_company_reply = fields.Boolean(
        string='Company Reply',
        default=False,
        help='If enabled, this channel is only available to users in the '
             '"Отправитель от имени компании" group.',
    )

    _sql_constraints = [
        ('code_unique', 'UNIQUE(code)', 'The channel tag code must be unique.'),
    ]

    def _to_store_defaults(self, target):
        """Expose id and name to the JS store."""
        return ['id', 'name', 'code', 'is_company_reply']
