from odoo import models, fields


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

    student_id = fields.Many2one('res.users', required=True, ondelete='cascade')
    exam_id = fields.Many2one('encoach.exam.custom', required=True, ondelete='cascade')
    entity_id = fields.Many2one('encoach.entity', ondelete='set null')
    status = fields.Selection([
        ('in_progress', 'In Progress'),
        ('scoring', 'Scoring'),
        ('completed', 'Completed'),
        ('abandoned', 'Abandoned'),
    ], default='in_progress', required=True)
    started_at = fields.Datetime(default=fields.Datetime.now)
    finished_at = fields.Datetime()
    overall_band = fields.Float()
    cefr_level = fields.Char(size=10)
    listening_band = fields.Float()
    reading_band = fields.Float()
    writing_band = fields.Float()
    speaking_band = fields.Float()
    total_score = fields.Float()
    max_score = fields.Float()


class EncoachStudentAnswer(models.Model):
    _name = 'encoach.student.answer'
    _description = 'Student Answer'

    attempt_id = fields.Many2one('encoach.student.attempt', required=True, ondelete='cascade')
    question_id = fields.Many2one('encoach.question', required=True, ondelete='cascade')
    answer = fields.Text()
    score = fields.Float()
    is_correct = fields.Boolean()
    feedback = fields.Text()


class EncoachStudentScore(models.Model):
    _name = 'encoach.student.score'
    _description = 'Student Skill Score'

    attempt_id = fields.Many2one('encoach.student.attempt', required=True, ondelete='cascade')
    skill = fields.Char(size=50, required=True)
    band_score = fields.Float()
    raw_score = fields.Float()
    max_score = fields.Float()
    cefr_level = fields.Char(size=10)
    entity_id = fields.Many2one('encoach.entity', ondelete='set null')
