class OrdersBackend(ServiceBackend):
    service_path = "orders"
    model_class = OrdersModel
    _schema_draft = schemas.OrderFromCartDraftSchema
    _schema_update = schemas.OrderUpdateSchema
    _schema_query_response = schemas.OrderPagedQueryResponseSchema

    def urls(self):
        return [
            ("^$", "GET", self.query),
            ("^$", "POST", self.create),
            ("^key=(?P<key>[^/]+)$", "GET", self.get_by_key),
            ("^(?P<id>[^/]+)$", "GET", self.get_by_id),
            ("^key=(?P<key>[^/]+)$", "POST", self.update_by_key),
            ("^(?P<id>[^/]+)$", "POST", self.update_by_id),
            ("^(?P<id>[^/]+)$", "DELETE", self.delete_by_id),
        ]

    _actions = {
        "changeOrderState":
        update_enum_attribute("orderState", "order_state"),
        "changePaymentState":
        update_enum_attribute("paymentState", "payment_state"),
        "changeShipmentState":
        update_enum_attribute("shipmentState", "shipment_state"),
        "addDelivery":
        add_delivery(),
    }
class CartDiscountsBackend(ServiceBackend):
    service_path = "cart-discounts"
    model_class = CartDiscountsModel
    _schema_draft = schemas.CartDiscountDraftSchema
    _schema_update = schemas.CartDiscountUpdateSchema
    _schema_query_response = schemas.CartDiscountPagedQueryResponseSchema

    def urls(self):
        return [
            ("^$", "GET", self.query),
            ("^$", "POST", self.create),
            ("^(?P<id>[^/]+)$", "GET", self.get_by_id),
            ("^key=(?P<key>[^/]+)$", "GET", self.get_by_key),
            ("^(?P<id>[^/]+)$", "POST", self.update_by_id),
            ("^key=(?P<key>[^/]+)$", "POST", self.update_by_key),
            ("^(?P<id>[^/]+)$", "DELETE", self.delete_by_id),
            ("^key=(?P<key>[^/]+)$", "DELETE", self.delete_by_key),
        ]

    _actions = {
        "setKey": update_attribute("key", "key"),
        "changeSortOrder": update_attribute("sortOrder", "sort_order"),
        "changeTarget": update_enum_attribute("target", "target"),
        "changeIsActive": update_attribute("isActive", "is_active"),
        "setName": update_attribute("name", "name"),
        "setDescription": update_attribute("description", "description"),
        "setCartPredicate": update_attribute("cartPredicate", "cart_predicate"),
    }