# -*- coding: utf-8 -*-

from odoo import models, fields, api, _
from odoo.exceptions import ValidationError


class SkeenCitaBloqueo(models.Model):
    _name = 'skeen.cita.bloqueo'
    _description = 'Bloqueo de Agenda por Médico'
    _order = 'date desc'

    doctor_id = fields.Many2one('hr.employee', string='Médico', required=True)
    date = fields.Date(string='Fecha', required=True, index=True)
    all_day = fields.Boolean(string='Todo el día', default=False)
    time_from = fields.Float(string='Desde', default=9.0)
    time_to = fields.Float(string='Hasta', default=10.0)
    motivo = fields.Char(string='Motivo')

    @api.constrains('time_from', 'time_to', 'all_day')
    def _check_horas(self):
        for b in self:
            if not b.all_day and b.time_to <= b.time_from:
                raise ValidationError(_('La hora final debe ser mayor a la inicial'))
