# DataProductSpec — wb.sales: /supplier/sales, item-фильтр saleID 'S' (продажи;
# 'R'-возвраты — отдельный спек wb.returns на тот же endpoint).
apiVersion: specs.gwptd.io/v1alpha1
kind: DataProduct
metadata:
  name: wb.sales
  generation: 1
  lifecycle: active
contract:
  version: 1.0.0

source:
  marketplaceRef: wb
  mpId: 1
  authProfileRef: wb.statistics
  originRef: wb.statistics

request:
  method: GET
  path: /api/v1/supplier/sales
  query:
    dateFrom: {var: window.start_date}
  window:
    days: 7

transport:
  strategy: http.single

extract:
  itemsPath: "$[*]"
  filter: {field: saleID, prefix: "S"}
  businessKeyPaths: ["$.saleID"]

outputs:
  intake:
    table: wb_sales                    # INSERT-only журнал
    fields:
      payload_id:          {var: payload_id}
      mp_id:               {static: 1}
      sale_id:             {python_func: wb_sale_id_str}
      odid:                {json_path: $.odid}
      g_number:            {json_path: $.gNumber}
      srid:                {json_path: $.srid}
      sale_date_mp:        {python_func: wb_sale_date_mp}
      last_change_mp:      {python_func: wb_sale_last_change_mp}
      supplier_article:    {json_path: $.supplierArticle}
      nm_id:               {json_path: $.nmId}
      barcode:             {json_path: $.barcode}
      category:            {json_path: $.category}
      subject:             {json_path: $.subject}
      brand:               {json_path: $.brand}
      tech_size:           {json_path: $.techSize}
      total_price:         {json_path: $.totalPrice}
      discount_pct:        {json_path: $.discountPercent}
      spp:                 {json_path: $.spp}
      price_with_disc:     {json_path: $.priceWithDisc}
      for_pay:             {json_path: $.forPay}
      finished_price:      {json_path: $.finishedPrice}
      warehouse_name:      {json_path: $.warehouseName}
      oblast:              {json_path: $.oblastOkrugName}
      region_name:         {json_path: $.regionName}
      country_name:        {json_path: $.countryName}
      sticker:             {json_path: $.sticker}
      payment_sale_amount: {json_path: $.paymentSaleAmount}
      warehouse_type:      {json_path: $.warehouseType}
      is_realization:      {json_path: $.isRealization}
      is_supply:           {json_path: $.isSupply}
      income_id:           {json_path: $.incomeID}
