# -*- coding: utf-8 -*-
from django.urls import path
from .views import (
    # Warehouse
    WarehouseListView, WarehouseCreateView, WarehouseUpdateView, WarehouseDeleteView, SetDefaultWarehouseView,
    # Sale
    SaleListView, SaleCreateView, SaleUpdateView, SaleDeleteView, SaleDetailView,
    # Inventory
    InventoryListView, InventoryCreateView, InventoryDetailView, InventoryLineCreateBulkView,
    InventoryLineAddView, InventoryLineUpdateView, InventoryLineDeleteView,
    InventoryCompleteView, InventoryDeleteView,
    # Transfer
    TransferListView, TransferBulkCreateView, TransferDetailView, TransferDeleteView, GetProductStockView,
    # Reservation
    ReservationListView,
    # Stock
    StockListView, StockDetailView,
    # StockBatch
    StockBatchListView, StockBatchDetailView,
    # SaleBatchAllocation
    SaleBatchAllocationListView,
)
# Showcase views
from .views.showcase import ShowcaseListView, ShowcaseCreateView, ShowcaseUpdateView, ShowcaseDeleteView, SetDefaultShowcaseView
# WriteOff Document views
from .views.writeoff_document import (
    WriteOffDocumentListView, WriteOffDocumentCreateView, WriteOffDocumentDetailView,
    WriteOffDocumentAddItemView, WriteOffDocumentUpdateItemView, WriteOffDocumentRemoveItemView,
    WriteOffDocumentConfirmView, WriteOffDocumentCancelView
)
# Incoming Document views
from .views.incoming_document import (
    IncomingDocumentListView, IncomingDocumentCreateView, IncomingDocumentDetailView,
    IncomingDocumentAddItemView, IncomingDocumentUpdateItemView, IncomingDocumentRemoveItemView,
    IncomingDocumentConfirmView, IncomingDocumentCancelView
)
# Transformation views
from .views.transformation import (
    TransformationListView, TransformationCreateView, TransformationDetailView,
    TransformationAddInputView, TransformationAddOutputView,
    TransformationRemoveInputView, TransformationRemoveOutputView,
    TransformationConfirmView, TransformationCancelView
)
# Debug views
from .views.debug_views import debug_inventory_page
from . import views

app_name = 'inventory'

urlpatterns = [
    # Главная страница складского модуля
    path('', views.inventory_home, name='inventory-home'),

    # ==================== WAREHOUSE ====================
    path('warehouses/', WarehouseListView.as_view(), name='warehouse-list'),
    path('warehouses/create/', WarehouseCreateView.as_view(), name='warehouse-create'),
    path('warehouses/<int:pk>/edit/', WarehouseUpdateView.as_view(), name='warehouse-update'),
    path('warehouses/<int:pk>/delete/', WarehouseDeleteView.as_view(), name='warehouse-delete'),
    path('warehouses/<int:pk>/set-default/', SetDefaultWarehouseView.as_view(), name='warehouse-set-default'),

    # ==================== INCOMING BATCH (УДАЛЕНО) ====================
    # IncomingBatch и Incoming удалены. Используйте IncomingDocument вместо них.

    # ==================== SALE ====================
    path('sales/', SaleListView.as_view(), name='sale-list'),
    path('sales/create/', SaleCreateView.as_view(), name='sale-create'),
    path('sales/<int:pk>/', SaleDetailView.as_view(), name='sale-detail'),
    path('sales/<int:pk>/edit/', SaleUpdateView.as_view(), name='sale-update'),
    path('sales/<int:pk>/delete/', SaleDeleteView.as_view(), name='sale-delete'),

    # ==================== INVENTORY ====================
    path('inventory-ops/', InventoryListView.as_view(), name='inventory-list'),
    path('inventory-ops/create/', InventoryCreateView.as_view(), name='inventory-create'),
    path('inventory-ops/<int:pk>/', InventoryDetailView.as_view(), name='inventory-detail'),
    path('inventory-ops/<int:pk>/lines/add-bulk/', InventoryLineCreateBulkView.as_view(), name='inventory-lines-add'),
    # AJAX endpoints для работы со строками инвентаризации
    path('inventory-ops/<int:inventory_id>/lines/add/', InventoryLineAddView.as_view(), name='inventory-line-add'),
    path('inventory-ops/<int:inventory_id>/lines/<int:line_id>/update/', InventoryLineUpdateView.as_view(), name='inventory-line-update'),
    path('inventory-ops/<int:inventory_id>/lines/<int:line_id>/delete/', InventoryLineDeleteView.as_view(), name='inventory-line-delete'),
    path('inventory-ops/<int:inventory_id>/complete/', InventoryCompleteView.as_view(), name='inventory-complete'),
    path('inventory-ops/<int:pk>/delete/', InventoryDeleteView.as_view(), name='inventory-delete'),

    # ==================== WRITEOFF (одиночные записи) ====================
    # УДАЛЕНО: пользователи работают только через WriteOffDocument
    # Модель WriteOff остаётся - она используется для хранения фактических списаний
    # Записи WriteOff создаются автоматически при проведении документов списания

    # ==================== WRITEOFF DOCUMENT (документы списания) ====================
    path('writeoff-documents/', WriteOffDocumentListView.as_view(), name='writeoff-document-list'),
    path('writeoff-documents/create/', WriteOffDocumentCreateView.as_view(), name='writeoff-document-create'),
    path('writeoff-documents/<int:pk>/', WriteOffDocumentDetailView.as_view(), name='writeoff-document-detail'),
    path('writeoff-documents/<int:pk>/add-item/', WriteOffDocumentAddItemView.as_view(), name='writeoff-document-add-item'),
    path('writeoff-documents/<int:pk>/update-item/<int:item_pk>/', WriteOffDocumentUpdateItemView.as_view(), name='writeoff-document-update-item'),
    path('writeoff-documents/<int:pk>/remove-item/<int:item_pk>/', WriteOffDocumentRemoveItemView.as_view(), name='writeoff-document-remove-item'),
    path('writeoff-documents/<int:pk>/confirm/', WriteOffDocumentConfirmView.as_view(), name='writeoff-document-confirm'),
    path('writeoff-documents/<int:pk>/cancel/', WriteOffDocumentCancelView.as_view(), name='writeoff-document-cancel'),

    # ==================== INCOMING (документы поступления) ====================
    path('incoming/', IncomingDocumentListView.as_view(), name='incoming-list'),
    path('incoming/create/', IncomingDocumentCreateView.as_view(), name='incoming-create'),
    path('incoming/<int:pk>/', IncomingDocumentDetailView.as_view(), name='incoming-detail'),
    path('incoming/<int:pk>/add-item/', IncomingDocumentAddItemView.as_view(), name='incoming-add-item'),
    path('incoming/<int:pk>/update-item/<int:item_pk>/', IncomingDocumentUpdateItemView.as_view(), name='incoming-update-item'),
    path('incoming/<int:pk>/remove-item/<int:item_pk>/', IncomingDocumentRemoveItemView.as_view(), name='incoming-remove-item'),
    path('incoming/<int:pk>/confirm/', IncomingDocumentConfirmView.as_view(), name='incoming-confirm'),
    path('incoming/<int:pk>/cancel/', IncomingDocumentCancelView.as_view(), name='incoming-cancel'),

    # ==================== TRANSFER ====================
    path('transfers/', TransferListView.as_view(), name='transfer-list'),
    path('transfers/create/', TransferBulkCreateView.as_view(), name='transfer-create'),  # Новая форма массового перемещения
    path('transfers/<int:pk>/', TransferDetailView.as_view(), name='transfer-detail'),  # Деталь документа
    path('transfers/<int:pk>/delete/', TransferDeleteView.as_view(), name='transfer-delete'),
    path('api/product-stock/', GetProductStockView.as_view(), name='api-product-stock'),  # API для получения количества товара

    # ==================== RESERVATION (READ ONLY) ====================
    path('reservations/', ReservationListView.as_view(), name='reservation-list'),

    # ==================== STOCK (READ ONLY) ====================
    path('stock/', StockListView.as_view(), name='stock-list'),
    path('stock/<int:pk>/', StockDetailView.as_view(), name='stock-detail'),

    # ==================== BATCH (READ ONLY) ====================
    path('batches/', StockBatchListView.as_view(), name='batch-list'),
    path('batches/<int:pk>/', StockBatchDetailView.as_view(), name='batch-detail'),

    # ==================== ALLOCATION (READ ONLY) ====================
    path('allocations/', SaleBatchAllocationListView.as_view(), name='allocation-list'),

    # ==================== SHOWCASE ====================
    path('showcases/', ShowcaseListView.as_view(), name='showcase-list'),
    path('showcases/create/', ShowcaseCreateView.as_view(), name='showcase-create'),
    path('showcases/<int:pk>/edit/', ShowcaseUpdateView.as_view(), name='showcase-update'),
    path('showcases/<int:pk>/delete/', ShowcaseDeleteView.as_view(), name='showcase-delete'),
    path('showcases/<int:pk>/set-default/', SetDefaultShowcaseView.as_view(), name='showcase-set-default'),

    # ==================== TRANSFORMATION ====================
    path('transformations/', TransformationListView.as_view(), name='transformation-list'),
    path('transformations/create/', TransformationCreateView.as_view(), name='transformation-create'),
    path('transformations/<int:pk>/', TransformationDetailView.as_view(), name='transformation-detail'),
    path('transformations/<int:pk>/add-input/', TransformationAddInputView.as_view(), name='transformation-add-input'),
    path('transformations/<int:pk>/add-output/', TransformationAddOutputView.as_view(), name='transformation-add-output'),
    path('transformations/<int:pk>/remove-input/<int:item_pk>/', TransformationRemoveInputView.as_view(), name='transformation-remove-input'),
    path('transformations/<int:pk>/remove-output/<int:item_pk>/', TransformationRemoveOutputView.as_view(), name='transformation-remove-output'),
    path('transformations/<int:pk>/confirm/', TransformationConfirmView.as_view(), name='transformation-confirm'),
    path('transformations/<int:pk>/cancel/', TransformationCancelView.as_view(), name='transformation-cancel'),

    # ==================== DEBUG (SUPERUSER ONLY) ====================
    path('debug/', debug_inventory_page, name='debug_page'),
]
