from odoo import models, fields


class LogisticsNodeConnection(models.Model):
    _name = 'logistics.node.connection'
    _description = 'Logistics Node Connection'
    _order = 'node_id, id'

    node_id = fields.Many2one(
        'logistics.node',
        string='Logistics Node',
        required=True,
        ondelete='cascade',
        help='The logistics node this connection belongs to'
    )
    
    name = fields.Char(
        string='Connection Name',
        required=True,
        help='Name of this connection (e.g., "Auto Terminal", "Railway Platform")'
    )
    
    # Deprecated field for backward compatibility
    connection_type = fields.Selection([
        ('auto', 'Automotive'),
        ('rail', 'Railway'),
        ('river', 'River'),
        ('sea', 'Maritime'),
    ], string='Connection Type (Deprecated)')
    
    transport_category_id = fields.Many2one(
        'logistics.transport.category',
        string='Transport Category',
        required=True,
        help='What type of transport can use this connection'
    )
    
    loading_type_id = fields.Many2one(
        'logistics.loading.type',
        string='Loading Type',
        required=True,
        help='How cargo is loaded at this connection'
    )
    
    active = fields.Boolean(
        string='Active',
        default=True
    )

    def name_get(self):
        result = []
        for record in self:
            result.append((record.id, record.name))
        return result