# -*- coding: utf-8 -*-
# Copyright 2026 Nexa Systems Inc.
# License OPL-1 (Odoo Proprietary License v1.0)

from odoo import models, fields


class FusionSyncStock(models.Model):
    _name = 'fusion.sync.stock'
    _description = 'Per-Warehouse Remote Stock Level'
    _rec_name = 'sync_warehouse_id'
    _order = 'sync_warehouse_id'

    mapping_id = fields.Many2one(
        'fusion.product.sync.mapping', string='Product Mapping',
        required=True, ondelete='cascade', index=True)
    sync_warehouse_id = fields.Many2one(
        'fusion.sync.warehouse', string='Remote Warehouse',
        required=True, ondelete='cascade', index=True)
    config_id = fields.Many2one(
        related='mapping_id.config_id', store=True, index=True)
    qty_available = fields.Float(string='On Hand', default=0.0)
    qty_forecast = fields.Float(string='Forecast', default=0.0)
    last_sync = fields.Datetime(string='Last Updated')

    _sql_constraints = [
        ('unique_mapping_warehouse',
         'UNIQUE(mapping_id, sync_warehouse_id)',
         'Only one stock record per product mapping per warehouse.'),
    ]
