from odoo import models, fields


class EncoachStudentAttempt(models.Model):
    _name = 'encoach.student.attempt'
    _description = 'Student Exam Attempt'

    student_id = fields.Many2one('res.users', required=True, ondelete='cascade', index=True)
    exam_id = fields.Many2one('encoach.exam.custom', ondelete='set null')
    started_at = fields.Datetime(default=fields.Datetime.now)
    completed_at = fields.Datetime()
    status = fields.Selection([
        ('in_progress', 'In Progress'),
        ('completed', 'Completed'),
        ('scoring', 'Scoring'),
        ('scored', 'Scored'),
        ('released', 'Released'),
        ('pending_approval', 'Pending Approval'),
    ], default='in_progress', required=True)
    listening_band = fields.Float()
    reading_band = fields.Float()
    writing_band = fields.Float()
    speaking_band = fields.Float()
    overall_band = fields.Float()
    cefr_level = fields.Selection([
        ('pre_a1', 'Pre-A1'),
        ('a1', 'A1'),
        ('a2', 'A2'),
        ('b1', 'B1'),
        ('b2', 'B2'),
        ('c1', 'C1'),
        ('c2', 'C2'),
    ])
    is_placement = fields.Boolean(default=False)
    entity_id = fields.Many2one('encoach.entity', ondelete='set null')
    released_at = fields.Datetime()
    released_by = fields.Many2one('res.users', ondelete='set null')
    answer_ids = fields.One2many('encoach.student.answer', 'attempt_id')
    score_ids = fields.One2many('encoach.score', 'attempt_id')
    autosave_data = fields.Text()
    feedback_ids = fields.One2many('encoach.feedback', 'attempt_id')
