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

class ReservationPeakHour(models.Model):
    _name = 'reservation.peak.hour'
    _description = 'Restaurant Peak Hour Duration'

    schedule_id = fields.Many2one('reservation.schedule', string='Schedule', ondelete='cascade')
    start_time = fields.Float(string='Peak Start Time', required=True)
    end_time = fields.Float(string='Peak End Time', required=True)
    
    slot_duration = fields.Selection([
        ('0.5', '30 Minutes'),
        ('1.0', '1 Hour'),
        ('1.5', '1.5 Hours'),
        ('2.0', '2 Hours'),
    ], string='Peak Slot Duration', default='1.0', required=True)

    @api.constrains('start_time', 'end_time')
    def _check_times(self):
        for rec in self:
            if rec.start_time >= rec.end_time:
                raise ValidationError(_("Peak start time must be before end time."))
