from odoo import api, models, fields


FAQ_AUDIENCE = [
    ('all', 'All'),
    ('both', 'Both (Student + Entity)'),
    ('student', 'Students'),
    ('teacher', 'Teachers'),
    ('admin', 'Admins'),
    ('entity', 'Entity Users'),
]


class EncoachFaqCategory(models.Model):
    _name = 'encoach.faq.category'
    _description = 'FAQ Category'
    _order = 'sequence, id'

    name = fields.Char(required=True)
    sequence = fields.Integer(default=10)
    audience = fields.Selection(FAQ_AUDIENCE, default='all')
    is_published = fields.Boolean(default=True)
    item_ids = fields.One2many('encoach.faq.item', 'category_id')
    item_count = fields.Integer(compute='_compute_item_count', store=True)

    @api.depends('item_ids')
    def _compute_item_count(self):
        for rec in self:
            rec.item_count = len(rec.item_ids)


class EncoachFaqItem(models.Model):
    _name = 'encoach.faq.item'
    _description = 'FAQ Item'
    _order = 'sequence, id'

    category_id = fields.Many2one('encoach.faq.category', required=True, ondelete='cascade')
    question = fields.Char(required=True)
    answer = fields.Text(required=True)
    sequence = fields.Integer(default=10)
    audience = fields.Selection(FAQ_AUDIENCE, default='all')
    is_published = fields.Boolean(default=True)
    video_url = fields.Char(help='Optional walkthrough video URL.')
