from odoo import models, fields


class LogisticsVehicleType(models.Model):
    _name = 'logistics.vehicle.type'
    _description = 'Logistics Vehicle Type'
    _order = 'transport_category_id, name'

    name = fields.Char(
        string='Vehicle Type Name',
        required=True,
        help='Name of the vehicle type (e.g., Truck, Railway Car, Ship)'
    )
    
    transport_category_id = fields.Many2one(
        'logistics.transport.category',
        string='Transport Category',
        required=True,
        help='Category of transport (auto, rail, sea, river)'
    )
    
    loading_type_id = fields.Many2one(
        'logistics.loading.type',
        string='Loading Type',
        required=True,
        help='Type of cargo loading method'
    )
    
    attribute_line_ids = fields.One2many(
        'logistics.transport.attribute.line',
        'vehicle_type_id',
        string='Attributes',
        help='Transport attributes and their values'
    )
    
    active = fields.Boolean(
        string='Active',
        default=True
    )

    def name_get(self):
        result = []
        for record in self:
            category = record.transport_category_id.name if record.transport_category_id else ''
            name = f"{record.name} ({category})" if category else record.name
            result.append((record.id, name))
        return result