from odoo import models, fields


class LogisticsTransportCategory(models.Model):
    _name = 'logistics.transport.category'
    _description = 'Transport Category'
    _order = 'sequence, name'

    name = fields.Char(
        string='Category Name',
        required=True,
        help='Name of transport category (e.g., "Railway", "Automotive")'
    )
    
    code = fields.Char(
        string='Code',
        required=True,
        help='Short code for this category (e.g., "rail", "auto")'
    )
    
    sequence = fields.Integer(
        string='Sequence',
        default=10,
        help='Sequence for ordering categories'
    )
    
    tag_ids = fields.One2many(
        'logistics.transport.category.tag',
        'category_id',
        string='Category Tags',
        help='Detailed tags for this transport category'
    )
    
    active = fields.Boolean(
        string='Active',
        default=True
    )

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


class LogisticsTransportCategoryTag(models.Model):
    _name = 'logistics.transport.category.tag'
    _description = 'Transport Category Tag'
    _order = 'category_id, sequence, name'

    name = fields.Char(
        string='Tag Name',
        required=True,
        help='Name of the tag (e.g., "Express", "Freight", "Local")'
    )
    
    category_id = fields.Many2one(
        'logistics.transport.category',
        string='Transport Category',
        required=True,
        ondelete='cascade',
        help='Related transport category'
    )
    
    sequence = fields.Integer(
        string='Sequence',
        default=10,
        help='Sequence for ordering tags'
    )
    
    active = fields.Boolean(
        string='Active',
        default=True
    )

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


class LogisticsLoadingType(models.Model):
    _name = 'logistics.loading.type'
    _description = 'Loading Type'
    _order = 'sequence, name'

    name = fields.Char(
        string='Loading Type Name',
        required=True,
        help='Name of loading type (e.g., "Container Loading", "Bulk Loading")'
    )
    
    code = fields.Char(
        string='Code',
        required=True,
        help='Short code for this loading type (e.g., "container", "bulk")'
    )
    
    sequence = fields.Integer(
        string='Sequence',
        default=10,
        help='Sequence for ordering loading types'
    )
    
    tag_ids = fields.One2many(
        'logistics.loading.type.tag',
        'loading_type_id',
        string='Loading Type Tags',
        help='Detailed tags for this loading type'
    )
    
    active = fields.Boolean(
        string='Active',
        default=True
    )

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


class LogisticsLoadingTypeTag(models.Model):
    _name = 'logistics.loading.type.tag'
    _description = 'Loading Type Tag'
    _order = 'loading_type_id, sequence, name'

    name = fields.Char(
        string='Tag Name',
        required=True,
        help='Name of the tag (e.g., "20ft", "40ft", "Refrigerated")'
    )
    
    loading_type_id = fields.Many2one(
        'logistics.loading.type',
        string='Loading Type',
        required=True,
        ondelete='cascade',
        help='Related loading type'
    )
    
    sequence = fields.Integer(
        string='Sequence',
        default=10,
        help='Sequence for ordering tags'
    )
    
    active = fields.Boolean(
        string='Active',
        default=True
    )

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