from odoo import models, fields


class EncoachDomain(models.Model):
    _name = 'encoach.domain'
    _description = 'Taxonomy Domain'
    _order = 'sequence, name'

    name = fields.Char(required=True, index=True)
    subject_id = fields.Many2one('encoach.subject', required=True, ondelete='cascade', index=True)
    description = fields.Text()
    sequence = fields.Integer(default=10)
    active = fields.Boolean(default=True)
    topic_ids = fields.One2many('encoach.topic', 'domain_id', string='Topics')

    def to_api_dict(self):
        self.ensure_one()
        return {
            'id': self.id,
            'name': self.name,
            'subject_id': self.subject_id.id,
            'subject_name': self.subject_id.name,
            'description': self.description or '',
            'active': self.active,
        }
