<?php

namespace KupShop\GraphQLBundle\Tests\ApiPos;

class PosQueryUtils
{
    public static function posAdditionalData($idPos): string
    {
        return "{
            posAdditionalData(idPos: {$idPos}) {
              vats {
                 items {
                   description,
                   vat,
                   default
                 }
               },
               shopCurrencySymbol,
               shopCurrency
            }
          }";
    }

    public static function loadOrder($id): string
    {
        return "query Order {
          order(id: {$id}) {
            id
            code
            cancelled
        
            warehouse {
              id
              box
              dateClose
              errors {
                items {
                  code
                  pieces
                  message
                }
              }
            }
        
            orderUser {
              name
              surname
              id
              email
              bonusPoints
              priceLevel {
                name
              }
              invoiceAddress {
                street
                city
              }
              note
            }
            isPaid
            invoiceAddress {
              name
              surname
              firm
            }
            totalPrice {
              withVat
              withoutVat
            }
            remainingPayment {
              price
            }
            items {
              id
              code
              chargeId
              productId
              variationId
              pieces
              piecePrice {
                withVat
                withoutVat
              }
              stores {
                items {
                  id
                  name
                  inStore
                }
              }
              warehouse {
                items {
                  code
                  pieces
                }
              }
              vat
              name
              serialNumbers {
                items {
                  code
                  valid
                }
              }
              product {
                ean
                photos {
                  source
                }
              }
            }
          }
        }
        ";
    }

    public static function finishOrder($id): string
    {
        return "mutation {
            posOrderFinish(
                id: {$id}
            ){
                idOrder
                status
                exception
            }
        }";
    }

    public static function confirmPayment($id, $uuidPayment, $method, $price): string
    {
        return "mutation {
           confirmPayment(idOrder: {$id}, uuidPayment: \"{$uuidPayment}\", paidPrice: \"{$price}\", methodPayment: \"{$method}\"){
            saved
            orderInfo {
              idOrder
              noOrder
              isPaid
              remainingPayment
              status
              uuidPayment
           }
         }
        }";
    }

    public static function posUpdateAndRecalculate($idOrder, $items, $user, $paymentMethod, $paidPrice, $savePurchase, $purchase, $newProducts = 'null'): string
    {
        return "mutation {
              posOrderUpdateAndRecalculate (
                 idOrder: {$idOrder}   
                 orderItems: {$items},
                 couponItems: []
                 user: {$user}
                 paidPrice: \"{$paidPrice}\"
                 savePurchase: {$savePurchase}
                 methodPayment: \"{$paymentMethod}\"
                 purchase: {$purchase}
                 newProducts: {$newProducts}
             ){
               saved,
               orderInfo {
                 idOrder
                 noOrder
                 isPaid
                 remainingPayment
                 status
                 uuidPayment
                 warehouse {
                   id
                   box
                   errors{
                     items{
                       code
                       pieces
                       message
                     }
                   }
                 }
               }
               items {
                 uuid,
                 id,
                 idProduct,
                 idVariation
                 piecePrice,
                 title,
                 variationTitle,
                 pieces,
                 vat,
                 ean,
                 stockIn,
                 serialNumberRequire,
                 stores {
                   items {
                     id,
                     name,
                     inStore
                   }
                 },
                 warehouse {
                  items{
                    id,
                    code,
                    pieces
                  }
                },
                serialNumbers {
                   items{
                    code,
                    valid
                  }
                }
               },
               discounts {
                 price {
                   withVat,
                   withoutVat,
                   vat
                 },
                 name,
                 valid,
                 value,
                 note,
                 type
               },
               charges {
                  name,
                  id,
                  chargeId,
                  price {
                    withoutVat,
                    withVat,
                    vat
                  }
               }
               loadedCoupons,
               loadedProducts,
               priceWithVat,
               priceWithoutVat,
               exception
             }
           }";
    }
}
