from odoo import models, fields, api, _


class ProductCategory(models.Model):
    _name = 'products.category'
    _description = 'Product Category'
    _order = 'sequence, name'
    _parent_store = True

    uuid = fields.Char('UUID', required=True, index=True)
    hs_code = fields.Char('HS Code', index=True)
    name = fields.Char('Name', required=True)
    sequence = fields.Integer('Sequence', default=10)
    parent_id = fields.Many2one('products.category', 'Parent Category', ondelete='cascade')
    parent_path = fields.Char(index=True)
    level = fields.Integer('Level', default=0)
    
    # Relations
    product_ids = fields.One2many('products.product', 'category_id', 'Products')
    
    # Computed
    product_count = fields.Integer('Products Count', compute='_compute_product_count')
    
    @api.depends('product_ids')
    def _compute_product_count(self):
        for record in self:
            record.product_count = len(record.product_ids)
    
    _sql_constraints = [
        ('uuid_unique', 'unique(uuid)', 'Category UUID must be unique'),
        ('hs_code_unique', 'unique(hs_code)', 'HS Code must be unique'),
    ]
