from odoo import models, fields, api
import logging

_logger = logging.getLogger(__name__)


class LogisticsIsochrone(models.Model):
    _name = 'logistics.isochrone'
    _description = 'Logistics Node Isochrone'
    _order = 'duration_minutes desc, create_date desc'

    node_id = fields.Many2one(
        'logistics.node',
        string='Logistics Node',
        required=True,
        ondelete='cascade',
        help='The logistics node this isochrone belongs to'
    )
    
    duration_minutes = fields.Integer(
        string='Duration (minutes)',
        required=True,
        help='Travel time in minutes for this isochrone'
    )
    
    uuid = fields.Char(
        string='UUID',
        required=True,
        help='UUID from ArangoDB document'
    )
    
    create_date = fields.Datetime(
        string='Created',
        default=fields.Datetime.now,
        help='When this isochrone was generated'
    )
    
    
    @api.depends('node_id.name', 'duration_minutes')
    def _compute_display_name(self):
        for record in self:
            record.display_name = f"{record.node_id.name} - {record.duration_minutes}min"
    
    display_name = fields.Char(
        string='Display Name',
        compute='_compute_display_name',
        store=True
    )
    
