# -*- coding: utf-8 -*-
from odoo import models, fields


class ShopifyPublication(models.Model):
    """
    Representa un canal de venta (publication) de Shopify.
    Ej: Point of Sale, Online Store, Facebook & Instagram, etc.
    Se carga dinámicamente desde la API GraphQL de Shopify.
    """
    _name = 'shopify.publication'
    _description = 'Canal de Venta Shopify'
    _order = 'name'

    name = fields.Char(
        string='Nombre del canal',
        required=True,
        readonly=True,
    )
    shopify_publication_id = fields.Char(
        string='ID Publicación Shopify (GID)',
        required=True,
        readonly=True,
        index=True,
        help="ID global de Shopify, ej: gid://shopify/Publication/12345",
    )
    config_id = fields.Many2one(
        'shopify.config',
        string='Tienda Shopify',
        required=True,
        ondelete='cascade',
        readonly=True,
    )

    _sql_constraints = [
        ('unique_pub_per_config',
         'UNIQUE(shopify_publication_id, config_id)',
         'Ya existe este canal de venta para esta tienda.'),
    ]
