from odoo import models, fields


class EncoachStudentAbilityModel(models.Model):
    _name = 'encoach.student.ability.model'
    _description = 'Student Ability Estimate per Skill'

    student_id = fields.Many2one('res.users', required=True, ondelete='cascade', index=True)
    subject_id = fields.Many2one('encoach.subject', ondelete='set null')
    skill = fields.Selection([
        ('listening', 'Listening'),
        ('reading', 'Reading'),
        ('writing', 'Writing'),
        ('speaking', 'Speaking'),
        ('grammar', 'Grammar'),
        ('vocabulary', 'Vocabulary'),
    ])
    theta = fields.Float(default=0.0)
    sem = fields.Float(default=1.0)
    last_updated = fields.Datetime(default=fields.Datetime.now)

    _sql_constraints = [
        ('unique_student_subject_skill',
         'unique(student_id, subject_id, skill)',
         'Duplicate ability record'),
    ]
