from odoo import models, fields, api, _


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

    uuid = fields.Char('UUID', required=True, index=True)
    name = fields.Char('Name', required=True)
    sequence = fields.Integer('Sequence', default=10)
    
    # 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'),
        ('name_unique', 'unique(name)', 'Category name must be unique'),
    ]