from odoo import models, fields, api, _


class Product(models.Model):
    _name = 'products.product'
    _description = 'Product'
    _order = 'category_id, name'

    uuid = fields.Char('UUID', required=True, index=True)
    name = fields.Char('Name', required=True)
    category_id = fields.Many2one('products.category', 'Category', required=True, ondelete='cascade')
    terminus_schema_id = fields.Char('TerminusDB Schema ID', help='ID схемы в TerminusDB (например: Cocoa)')
    
    # Relations (will be available after offers/requests modules installation)
    
    # Computed
    category_name = fields.Char('Category', related='category_id.name', store=True)
    
    def name_get(self):
        result = []
        for record in self:
            name = f"[{record.category_name}] {record.name}"
            result.append((record.id, name))
        return result
    
    _sql_constraints = [
        ('uuid_unique', 'unique(uuid)', 'Product UUID must be unique'),
    ]