from odoo import fields, models


class EncoachTicket(models.Model):
    _name = 'encoach.ticket'
    _description = 'Support Ticket'
    _inherit = ['mail.thread']
    _order = 'id desc'

    subject = fields.Char('Subject', required=True, tracking=True)
    description = fields.Text('Description')
    type = fields.Selection([
        ('bug', 'Bug'),
        ('feature', 'Feature'),
        ('help', 'Help'),
        ('support', 'Support'),
        ('feedback', 'Feedback'),
    ], string='Type', default='support', required=True, tracking=True)
    status = fields.Selection([
        ('open', 'Open'),
        ('in_progress', 'In Progress'),
        ('resolved', 'Resolved'),
        ('closed', 'Closed'),
    ], string='Status', default='open', required=True, tracking=True)
    source = fields.Selection([
        ('platform', 'Platform'),
        ('webpage', 'Webpage'),
        ('email', 'Email'),
    ], string='Source', default='platform')

    page_context = fields.Char('Page Context')
    reporter_id = fields.Many2one('res.users', string='Reporter', required=True,
                                  default=lambda self: self.env.user.id)
    assignee_id = fields.Many2one('res.users', string='Assignee')
    entity_id = fields.Many2one('encoach.entity', string='Entity')

    resolved_at = fields.Datetime('Resolved At')
