from django.utils.translation import gettext_lazy as _
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiParameter, extend_schema
from rest_framework import status

from engine.core.docs.drf import BASE_ERRORS
from engine.core.serializers import (
    AddOrderProductSerializer,
    AddressSerializer,
    AddWishlistProductSerializer,
    AttributeDetailSerializer,
    AttributeGroupDetailSerializer,
    AttributeGroupSimpleSerializer,
    AttributeSimpleSerializer,
    AttributeValueDetailSerializer,
    AttributeValueSimpleSerializer,
    BrandDetailSerializer,
    BrandSimpleSerializer,
    BulkAddOrderProductsSerializer,
    BulkAddWishlistProductSerializer,
    BulkRemoveOrderProductsSerializer,
    BulkRemoveWishlistProductSerializer,
    BuyOrderSerializer,
    BuyUnregisteredOrderSerializer,
    CategoryDetailSerializer,
    CategorySimpleSerializer,
    FeedbackDetailSerializer,
    FeedbackSimpleSerializer,
    OrderDetailSerializer,
    OrderProductDetailSerializer,
    OrderProductSimpleSerializer,
    OrderSimpleSerializer,
    ProductDetailSerializer,
    ProductImageDetailSerializer,
    ProductImageSimpleSerializer,
    ProductSimpleSerializer,
    ProductTagDetailSerializer,
    ProductTagSimpleSerializer,
    PromoCodeDetailSerializer,
    PromoCodeSimpleSerializer,
    PromotionDetailSerializer,
    PromotionSimpleSerializer,
    RemoveOrderProductSerializer,
    RemoveWishlistProductSerializer,
    StockDetailSerializer,
    StockSimpleSerializer,
    VendorDetailSerializer,
    VendorSimpleSerializer,
    WishlistDetailSerializer,
    WishlistSimpleSerializer,
)
from engine.core.serializers.seo import SeoSnapshotSerializer
from engine.core.serializers.utility import (
    AddressCreateSerializer,
    AddressSuggestionSerializer,
    DoFeedbackSerializer,
)
from engine.payments.serializers import TransactionProcessSerializer

ATTRIBUTE_GROUP_SCHEMA = {
    "list": extend_schema(
        tags=[
            "attributeGroups",
        ],
        summary=_("list all attribute groups (simple view)"),
        responses={
            status.HTTP_200_OK: AttributeGroupSimpleSerializer(many=True),
            **BASE_ERRORS,
        },
    ),
    "retrieve": extend_schema(
        tags=[
            "attributeGroups",
        ],
        summary=_("retrieve a single attribute group (detailed view)"),
        responses={status.HTTP_200_OK: AttributeGroupDetailSerializer(), **BASE_ERRORS},
    ),
    "create": extend_schema(
        tags=[
            "attributeGroups",
        ],
        summary=_("create an attribute group"),
        responses={
            status.HTTP_201_CREATED: AttributeGroupDetailSerializer(),
            **BASE_ERRORS,
        },
    ),
    "destroy": extend_schema(
        tags=[
            "attributeGroups",
        ],
        summary=_("delete an attribute group"),
        responses={status.HTTP_204_NO_CONTENT: {}, **BASE_ERRORS},
    ),
    "update": extend_schema(
        tags=[
            "attributeGroups",
        ],
        summary=_("rewrite an existing attribute group saving non-editables"),
        responses={status.HTTP_200_OK: AttributeGroupDetailSerializer(), **BASE_ERRORS},
    ),
    "partial_update": extend_schema(
        tags=[
            "attributeGroups",
        ],
        summary=_(
            "rewrite some fields of an existing attribute group saving non-editables"
        ),
        responses={status.HTTP_200_OK: AttributeGroupDetailSerializer(), **BASE_ERRORS},
    ),
}

ATTRIBUTE_SCHEMA = {
    "list": extend_schema(
        tags=[
            "attributes",
        ],
        summary=_("list all attributes (simple view)"),
        responses={
            status.HTTP_200_OK: AttributeSimpleSerializer(many=True),
            **BASE_ERRORS,
        },
    ),
    "retrieve": extend_schema(
        tags=[
            "attributes",
        ],
        summary=_("retrieve a single attribute (detailed view)"),
        responses={status.HTTP_200_OK: AttributeDetailSerializer(), **BASE_ERRORS},
    ),
    "create": extend_schema(
        tags=[
            "attributes",
        ],
        summary=_("create an attribute"),
        responses={status.HTTP_201_CREATED: AttributeDetailSerializer(), **BASE_ERRORS},
    ),
    "destroy": extend_schema(
        tags=[
            "attributes",
        ],
        summary=_("delete an attribute"),
        responses={status.HTTP_204_NO_CONTENT: {}, **BASE_ERRORS},
    ),
    "update": extend_schema(
        tags=[
            "attributes",
        ],
        summary=_("rewrite an existing attribute saving non-editables"),
        responses={status.HTTP_200_OK: AttributeDetailSerializer(), **BASE_ERRORS},
    ),
    "partial_update": extend_schema(
        tags=[
            "attributes",
        ],
        summary=_("rewrite some fields of an existing attribute saving non-editables"),
        responses={status.HTTP_200_OK: AttributeDetailSerializer(), **BASE_ERRORS},
    ),
}

ATTRIBUTE_VALUE_SCHEMA = {
    "list": extend_schema(
        tags=[
            "attributeValues",
        ],
        summary=_("list all attribute values (simple view)"),
        responses={
            status.HTTP_200_OK: AttributeValueSimpleSerializer(many=True),
            **BASE_ERRORS,
        },
    ),
    "retrieve": extend_schema(
        tags=[
            "attributeValues",
        ],
        summary=_("retrieve a single attribute value (detailed view)"),
        responses={status.HTTP_200_OK: AttributeValueDetailSerializer(), **BASE_ERRORS},
    ),
    "create": extend_schema(
        tags=[
            "attributeValues",
        ],
        summary=_("create an attribute value"),
        responses={
            status.HTTP_201_CREATED: AttributeValueDetailSerializer(),
            **BASE_ERRORS,
        },
    ),
    "destroy": extend_schema(
        tags=[
            "attributeValues",
        ],
        summary=_("delete an attribute value"),
        responses={status.HTTP_204_NO_CONTENT: {}, **BASE_ERRORS},
    ),
    "update": extend_schema(
        tags=[
            "attributeValues",
        ],
        summary=_("rewrite an existing attribute value saving non-editables"),
        responses={status.HTTP_200_OK: AttributeValueDetailSerializer(), **BASE_ERRORS},
    ),
    "partial_update": extend_schema(
        tags=[
            "attributeValues",
        ],
        summary=_(
            "rewrite some fields of an existing attribute value saving non-editables"
        ),
        responses={status.HTTP_200_OK: AttributeValueDetailSerializer(), **BASE_ERRORS},
    ),
}

CATEGORY_SCHEMA = {
    "list": extend_schema(
        tags=[
            "categories",
        ],
        summary=_("list all categories (simple view)"),
        description=_("list all categories (simple view)"),
        responses={
            status.HTTP_200_OK: CategorySimpleSerializer(many=True),
            **BASE_ERRORS,
        },
    ),
    "retrieve": extend_schema(
        tags=[
            "categories",
        ],
        summary=_("retrieve a single category (detailed view)"),
        description=_("retrieve a single category (detailed view)"),
        parameters=[
            OpenApiParameter(
                name="lookup_value",
                location="path",
                description=_("Category UUID or slug"),
                type=OpenApiTypes.STR,
            ),
        ],
        responses={status.HTTP_200_OK: CategoryDetailSerializer(), **BASE_ERRORS},
    ),
    "create": extend_schema(
        tags=[
            "categories",
        ],
        summary=_("create a category"),
        description=_("create a category"),
        responses={status.HTTP_201_CREATED: CategoryDetailSerializer(), **BASE_ERRORS},
    ),
    "destroy": extend_schema(
        tags=[
            "categories",
        ],
        summary=_("delete a category"),
        description=_("delete a category"),
        responses={status.HTTP_204_NO_CONTENT: {}, **BASE_ERRORS},
    ),
    "update": extend_schema(
        tags=[
            "categories",
        ],
        summary=_("rewrite an existing category saving non-editables"),
        description=_("rewrite an existing category saving non-editables"),
        responses={status.HTTP_200_OK: CategoryDetailSerializer(), **BASE_ERRORS},
    ),
    "partial_update": extend_schema(
        tags=[
            "categories",
        ],
        summary=_("rewrite some fields of an existing category saving non-editables"),
        description=_(
            "rewrite some fields of an existing category saving non-editables"
        ),
        responses={status.HTTP_200_OK: CategoryDetailSerializer(), **BASE_ERRORS},
    ),
    "seo_meta": extend_schema(
        tags=[
            "categories",
        ],
        summary=_("SEO Meta snapshot"),
        description=_("returns a snapshot of the category's SEO meta data"),
        parameters=[
            OpenApiParameter(
                name="lookup_value",
                location="path",
                description=_("Category UUID or slug"),
                type=OpenApiTypes.STR,
            ),
        ],
        responses={
            status.HTTP_200_OK: SeoSnapshotSerializer(),
            **BASE_ERRORS,
        },
    ),
}

ORDER_SCHEMA = {
    "list": extend_schema(
        tags=[
            "orders",
        ],
        summary=_("list all orders (simple view)"),
        description=_("for non-staff users, only their own orders are returned."),
        parameters=[
            OpenApiParameter(
                name="search",
                type=OpenApiTypes.STR,
                description=_(
                    "Case-insensitive substring search across human_readable_id, "
                    "order_products.product.name, and order_products.product.partnumber"
                ),
            ),
            OpenApiParameter(
                name="min_buy_time",
                type=OpenApiTypes.DATETIME,
                description=_("Filter orders with buy_time >= this ISO 8601 datetime"),
            ),
            OpenApiParameter(
                name="max_buy_time",
                type=OpenApiTypes.DATETIME,
                description=_("Filter orders with buy_time <= this ISO 8601 datetime"),
            ),
            OpenApiParameter(
                name="uuid",
                type=OpenApiTypes.UUID,
                description=_("Filter by exact order UUID"),
            ),
            OpenApiParameter(
                name="human_readable_id",
                type=OpenApiTypes.STR,
                description=_("Filter by exact human-readable order ID"),
            ),
            OpenApiParameter(
                name="user_email",
                type=OpenApiTypes.STR,
                description=_("Filter by user's email (case-insensitive exact match)"),
            ),
            OpenApiParameter(
                name="user",
                type=OpenApiTypes.UUID,
                description=_("Filter by user's UUID"),
            ),
            OpenApiParameter(
                name="status",
                type=OpenApiTypes.STR,
                description=_(
                    "Filter by order status (case-insensitive substring match)"
                ),
            ),
            OpenApiParameter(
                name="order_by",
                type=OpenApiTypes.STR,
                description=_(
                    "Order by one of: uuid, human_readable_id, user_email, user, "
                    "status, created, modified, buy_time, random. "
                    "Prefix with '-' for descending (e.g. '-buy_time')."
                ),
            ),
        ],
        responses={status.HTTP_200_OK: OrderSimpleSerializer(many=True), **BASE_ERRORS},
    ),
    "retrieve": extend_schema(
        tags=[
            "orders",
        ],
        summary=_("retrieve a single order (detailed view)"),
        parameters=[
            OpenApiParameter(
                name="lookup_value",
                location="path",
                description=_("Order UUID or human-readable id"),
                type=OpenApiTypes.STR,
            ),
        ],
        responses={status.HTTP_200_OK: OrderDetailSerializer(), **BASE_ERRORS},
    ),
    "create": extend_schema(
        tags=[
            "orders",
        ],
        summary=_("create an order"),
        description=_("doesn't work for non-staff users."),
        responses={status.HTTP_201_CREATED: OrderDetailSerializer(), **BASE_ERRORS},
    ),
    "destroy": extend_schema(
        tags=[
            "orders",
        ],
        summary=_("delete an order"),
        responses={status.HTTP_204_NO_CONTENT: {}, **BASE_ERRORS},
    ),
    "update": extend_schema(
        tags=[
            "orders",
        ],
        summary=_("rewrite an existing order saving non-editables"),
        responses={status.HTTP_200_OK: OrderDetailSerializer(), **BASE_ERRORS},
    ),
    "partial_update": extend_schema(
        tags=[
            "orders",
        ],
        summary=_("rewrite some fields of an existing order saving non-editables"),
        responses={status.HTTP_200_OK: OrderDetailSerializer(), **BASE_ERRORS},
    ),
    "buy": extend_schema(
        tags=[
            "orders",
        ],
        summary=_("purchase an order"),
        description=_(
            "finalizes the order purchase. if `force_balance` is used,"
            " the purchase is completed using the user's balance;"
            " if `force_payment` is used, a transaction is initiated."
        ),
        request=BuyOrderSerializer(),
        responses={
            status.HTTP_200_OK: OrderDetailSerializer(),
            status.HTTP_202_ACCEPTED: TransactionProcessSerializer(),
            **BASE_ERRORS,
        },
    ),
    "current": extend_schema(
        tags=[
            "orders",
        ],
        summary=_("retrieve current pending order of a user"),
        description=_("retrieves a current pending order of an authenticated user"),
        responses={
            status.HTTP_200_OK: OrderDetailSerializer(),
            **BASE_ERRORS,
        },
    ),
    "buy_unregistered": extend_schema(
        tags=[
            "orders",
        ],
        summary=_("purchase an order without account creation"),
        description=_("finalizes the order purchase for a non-registered user."),
        request=BuyUnregisteredOrderSerializer(),
        responses={
            status.HTTP_202_ACCEPTED: TransactionProcessSerializer(),
            **BASE_ERRORS,
        },
    ),
    "add_order_product": extend_schema(
        tags=[
            "orders",
        ],
        summary=_("add product to order"),
        description=_(
            "adds a product to an order using the provided `product_uuid` and `attributes`."
        ),
        request=AddOrderProductSerializer(),
        responses={status.HTTP_200_OK: OrderDetailSerializer(), **BASE_ERRORS},
    ),
    "bulk_add_order_products": extend_schema(
        tags=[
            "orders",
        ],
        summary=_("add a list of products to order, quantities will not count"),
        description=_(
            "adds a list of products to an order using the provided `product_uuid` and `attributes`."
        ),
        request=BulkAddOrderProductsSerializer(),
        responses={status.HTTP_200_OK: OrderDetailSerializer(), **BASE_ERRORS},
    ),
    "remove_order_product": extend_schema(
        tags=[
            "orders",
        ],
        summary=_("remove product from order"),
        description=_(
            "removes a product from an order using the provided `product_uuid` and `attributes`."
        ),
        request=RemoveOrderProductSerializer(),
        responses={status.HTTP_200_OK: OrderDetailSerializer(), **BASE_ERRORS},
    ),
    "bulk_remove_order_products": extend_schema(
        tags=[
            "orders",
        ],
        summary=_("remove product from order, quantities will not count"),
        description=_(
            "removes a list of products from an order using the provided `product_uuid` and `attributes`"
        ),
        request=BulkRemoveOrderProductsSerializer(),
        responses={status.HTTP_200_OK: OrderDetailSerializer(), **BASE_ERRORS},
    ),
}

WISHLIST_SCHEMA = {
    "list": extend_schema(
        tags=[
            "wishlists",
        ],
        summary=_("list all wishlists (simple view)"),
        description=_("for non-staff users, only their own wishlists are returned."),
        responses={
            status.HTTP_200_OK: WishlistSimpleSerializer(many=True),
            **BASE_ERRORS,
        },
    ),
    "retrieve": extend_schema(
        tags=[
            "wishlists",
        ],
        summary=_("retrieve a single wishlist (detailed view)"),
        responses={status.HTTP_200_OK: WishlistDetailSerializer(), **BASE_ERRORS},
    ),
    "create": extend_schema(
        tags=[
            "wishlists",
        ],
        summary=_("create an wishlist"),
        description=_("Doesn't work for non-staff users."),
        responses={status.HTTP_201_CREATED: WishlistDetailSerializer(), **BASE_ERRORS},
    ),
    "destroy": extend_schema(
        tags=[
            "wishlists",
        ],
        summary=_("delete an wishlist"),
        responses={status.HTTP_204_NO_CONTENT: {}, **BASE_ERRORS},
    ),
    "update": extend_schema(
        tags=[
            "wishlists",
        ],
        summary=_("rewrite an existing wishlist saving non-editables"),
        responses={status.HTTP_200_OK: WishlistDetailSerializer(), **BASE_ERRORS},
    ),
    "partial_update": extend_schema(
        tags=[
            "wishlists",
        ],
        summary=_("rewrite some fields of an existing wishlist saving non-editables"),
        responses={status.HTTP_200_OK: WishlistDetailSerializer(), **BASE_ERRORS},
    ),
    "current": extend_schema(
        tags=[
            "wishlists",
        ],
        summary=_("retrieve current pending wishlist of a user"),
        description=_("retrieves a current pending wishlist of an authenticated user"),
        responses={
            status.HTTP_200_OK: WishlistDetailSerializer(),
            **BASE_ERRORS,
        },
    ),
    "add_wishlist_product": extend_schema(
        tags=[
            "wishlists",
        ],
        summary=_("add product to wishlist"),
        description=_(
            "adds a product to an wishlist using the provided `product_uuid`"
        ),
        request=AddWishlistProductSerializer(),
        responses={status.HTTP_200_OK: WishlistDetailSerializer(), **BASE_ERRORS},
    ),
    "remove_wishlist_product": extend_schema(
        tags=[
            "wishlists",
        ],
        summary=_("remove product from wishlist"),
        description=_(
            "removes a product from an wishlist using the provided `product_uuid`"
        ),
        request=RemoveWishlistProductSerializer(),
        responses={status.HTTP_200_OK: WishlistDetailSerializer(), **BASE_ERRORS},
    ),
    "bulk_add_wishlist_products": extend_schema(
        tags=[
            "wishlists",
        ],
        summary=_("add many products to wishlist"),
        description=_(
            "adds many products to an wishlist using the provided `product_uuids`"
        ),
        request=BulkAddWishlistProductSerializer(),
        responses={status.HTTP_200_OK: WishlistDetailSerializer(), **BASE_ERRORS},
    ),
    "bulk_remove_wishlist_products": extend_schema(
        tags=[
            "wishlists",
        ],
        summary=_("remove many products from wishlist"),
        description=_(
            "removes many products from an wishlist using the provided `product_uuids`"
        ),
        request=BulkRemoveWishlistProductSerializer(),
        responses={status.HTTP_200_OK: WishlistDetailSerializer(), **BASE_ERRORS},
    ),
}

ATTRIBUTES_DESC = _(
    "Filter by one or more attribute name/value pairs.  \n"
    "• **Syntax**: `attr_name=method-value[;attr2=method2-value2]…`  \n"
    "• **Methods** (defaults to `icontains` if omitted): "
    "`iexact`, `exact`, `icontains`, `contains`, `isnull`, "
    "`startswith`, `istartswith`, `endswith`, `iendswith`, "
    "`regex`, `iregex`, `lt`, `lte`, `gt`, `gte`, `in`  \n"
    "• **Value typing**: JSON is attempted first (so you can pass lists/dicts), "
    "`true`/`false` for booleans, integers, floats; otherwise treated as string.  \n"
    "• **Base64**: prefix with `b64-` to URL-safe base64-encode the raw value.  \n"
    "Examples:  \n"
    '`color=exact-red`,  `size=gt-10`,  `features=in-["wifi","bluetooth"]`,  \n'
    "`b64-description=icontains-aGVhdC1jb2xk`"
)

PRODUCT_SCHEMA = {
    "list": extend_schema(
        tags=[
            "products",
        ],
        summary=_("list all products (simple view)"),
        description=_("list all products (simple view)"),
        parameters=[
            OpenApiParameter(
                name="uuid",
                location="query",
                description=_("(exact) Product UUID"),
                type=str,
            ),
            OpenApiParameter(
                name="order_by",
                location="query",
                description=_(
                    "Comma-separated list of fields to sort by. "
                    "Prefix with `-` for descending.  \n"
                    "**Allowed:** uuid, rating, name, slug, created, modified, price, random"
                ),
                required=False,
                type=str,
            ),
        ],
        responses={
            status.HTTP_200_OK: ProductSimpleSerializer(many=True),
            **BASE_ERRORS,
        },
    ),
    "retrieve": extend_schema(
        tags=[
            "products",
        ],
        summary=_("retrieve a single product (detailed view)"),
        description=_("retrieve a single product (detailed view)"),
        parameters=[
            OpenApiParameter(
                name="lookup_value",
                location="path",
                description=_("Product UUID or slug"),
                type=str,
            ),
        ],
        responses={
            status.HTTP_200_OK: ProductDetailSerializer(),
            **BASE_ERRORS,
        },
    ),
    "create": extend_schema(
        tags=[
            "products",
        ],
        summary=_("create a product"),
        description=_("create a product"),
        responses={
            status.HTTP_201_CREATED: ProductDetailSerializer(),
            **BASE_ERRORS,
        },
    ),
    "update": extend_schema(
        tags=[
            "products",
        ],
        summary=_("rewrite an existing product, preserving non-editable fields"),
        description=_("rewrite an existing product, preserving non-editable fields"),
        parameters=[
            OpenApiParameter(
                name="lookup_value",
                location="path",
                description=_("Product UUID or slug"),
                type=str,
            ),
        ],
        responses={
            status.HTTP_200_OK: ProductDetailSerializer(),
            **BASE_ERRORS,
        },
    ),
    "partial_update": extend_schema(
        tags=[
            "products",
        ],
        summary=_(
            "update some fields of an existing product, preserving non-editable fields"
        ),
        description=_(
            "update some fields of an existing product, preserving non-editable fields"
        ),
        parameters=[
            OpenApiParameter(
                name="lookup_value",
                location="path",
                description=_("Product UUID or slug"),
                type=str,
            ),
        ],
        responses={
            status.HTTP_200_OK: ProductDetailSerializer(),
            **BASE_ERRORS,
        },
    ),
    "destroy": extend_schema(
        tags=[
            "products",
        ],
        summary=_("delete a product"),
        description=_("delete a product"),
        parameters=[
            OpenApiParameter(
                name="lookup_value",
                location="path",
                description=_("Product UUID or slug"),
                type=str,
            ),
        ],
        responses={
            status.HTTP_204_NO_CONTENT: {},
            **BASE_ERRORS,
        },
    ),
    "feedbacks": extend_schema(
        tags=[
            "products",
        ],
        summary=_("lists all permitted feedbacks for a product"),
        description=_("lists all permitted feedbacks for a product"),
        parameters=[
            OpenApiParameter(
                name="lookup_value",
                location="path",
                description=_("Product UUID or slug"),
                type=str,
            ),
        ],
        responses={
            status.HTTP_200_OK: FeedbackSimpleSerializer(many=True),
            **BASE_ERRORS,
        },
    ),
    "seo_meta": extend_schema(
        tags=[
            "products",
        ],
        summary=_("SEO Meta snapshot"),
        description=_("returns a snapshot of the product's SEO meta data"),
        parameters=[
            OpenApiParameter(
                name="lookup_value",
                location="path",
                description=_("Product UUID or slug"),
                type=str,
            ),
        ],
        responses={
            status.HTTP_200_OK: SeoSnapshotSerializer(),
            **BASE_ERRORS,
        },
    ),
}

ADDRESS_SCHEMA = {
    "list": extend_schema(
        tags=[
            "addresses",
        ],
        summary=_("list all addresses"),
        responses={
            status.HTTP_200_OK: AddressSerializer(many=True),
            **BASE_ERRORS,
        },
    ),
    "retrieve": extend_schema(
        tags=[
            "addresses",
        ],
        summary=_("retrieve a single address"),
        responses={
            status.HTTP_200_OK: AddressSerializer(),
            **BASE_ERRORS,
        },
    ),
    "create": extend_schema(
        tags=[
            "addresses",
        ],
        summary=_("create a new address"),
        request=AddressCreateSerializer(),
        responses={
            status.HTTP_201_CREATED: AddressSerializer(),
            **BASE_ERRORS,
        },
    ),
    "destroy": extend_schema(
        tags=[
            "addresses",
        ],
        summary=_("delete an address"),
        responses={
            status.HTTP_204_NO_CONTENT: {},
            **BASE_ERRORS,
        },
    ),
    "update": extend_schema(
        tags=[
            "addresses",
        ],
        summary=_("update an entire address"),
        request=AddressSerializer(),
        responses={
            status.HTTP_200_OK: AddressSerializer(),
            **BASE_ERRORS,
        },
    ),
    "partial_update": extend_schema(
        tags=[
            "addresses",
        ],
        summary=_("partially update an address"),
        request=AddressSerializer(),
        responses={
            status.HTTP_200_OK: AddressSerializer(),
            **BASE_ERRORS,
        },
    ),
    "autocomplete": extend_schema(
        tags=[
            "addresses",
        ],
        summary=_("autocomplete address suggestions"),
        parameters=[
            OpenApiParameter(
                name="q",
                location="query",
                description=_(
                    "raw data query string, please append with data from geo-IP endpoint"
                ),
                type=str,
            ),
            OpenApiParameter(
                name="limit",
                location="query",
                description=_("limit the results amount, 1 < limit < 10, default: 5"),
                type=int,
            ),
        ],
        responses={
            status.HTTP_200_OK: AddressSuggestionSerializer(many=True),
            **BASE_ERRORS,
        },
    ),
}

FEEDBACK_SCHEMA = {
    "list": extend_schema(
        tags=[
            "feedbacks",
        ],
        summary=_("list all feedbacks (simple view)"),
        responses={
            status.HTTP_200_OK: FeedbackSimpleSerializer(many=True),
            **BASE_ERRORS,
        },
    ),
    "retrieve": extend_schema(
        tags=[
            "feedbacks",
        ],
        summary=_("retrieve a single feedback (detailed view)"),
        responses={status.HTTP_200_OK: FeedbackDetailSerializer(), **BASE_ERRORS},
    ),
    "create": extend_schema(
        tags=[
            "feedbacks",
        ],
        summary=_("create a feedback"),
        responses={status.HTTP_201_CREATED: FeedbackDetailSerializer(), **BASE_ERRORS},
    ),
    "destroy": extend_schema(
        tags=[
            "feedbacks",
        ],
        summary=_("delete a feedback"),
        responses={status.HTTP_204_NO_CONTENT: {}, **BASE_ERRORS},
    ),
    "update": extend_schema(
        tags=[
            "feedbacks",
        ],
        summary=_("rewrite an existing feedback saving non-editables"),
        responses={status.HTTP_200_OK: FeedbackDetailSerializer(), **BASE_ERRORS},
    ),
    "partial_update": extend_schema(
        tags=[
            "feedbacks",
        ],
        summary=_("rewrite some fields of an existing feedback saving non-editables"),
        responses={status.HTTP_200_OK: FeedbackDetailSerializer(), **BASE_ERRORS},
    ),
}

ORDER_PRODUCT_SCHEMA = {
    "list": extend_schema(
        tags=[
            "orderProducts",
        ],
        summary=_("list all order–product relations (simple view)"),
        responses={
            status.HTTP_200_OK: OrderProductSimpleSerializer(many=True),
            **BASE_ERRORS,
        },
    ),
    "retrieve": extend_schema(
        tags=[
            "orderProducts",
        ],
        summary=_("retrieve a single order–product relation (detailed view)"),
        responses={
            status.HTTP_200_OK: OrderProductDetailSerializer(),
            **BASE_ERRORS,
        },
    ),
    "create": extend_schema(
        tags=[
            "orderProducts",
        ],
        summary=_("create a new order–product relation"),
        responses={
            status.HTTP_201_CREATED: OrderProductDetailSerializer(),
            **BASE_ERRORS,
        },
    ),
    "update": extend_schema(
        tags=[
            "orderProducts",
        ],
        summary=_("replace an existing order–product relation"),
        responses={
            status.HTTP_200_OK: OrderProductDetailSerializer(),
            **BASE_ERRORS,
        },
    ),
    "partial_update": extend_schema(
        tags=[
            "orderProducts",
        ],
        summary=_("partially update an existing order–product relation"),
        responses={
            status.HTTP_200_OK: OrderProductDetailSerializer(),
            **BASE_ERRORS,
        },
    ),
    "destroy": extend_schema(
        tags=[
            "orderProducts",
        ],
        summary=_("delete an order–product relation"),
        responses={
            status.HTTP_204_NO_CONTENT: {},
            **BASE_ERRORS,
        },
    ),
    "do_feedback": extend_schema(
        tags=[
            "orderProducts",
        ],
        summary=_("add or remove feedback on an order–product relation"),
        request=DoFeedbackSerializer,
        responses={
            status.HTTP_201_CREATED: FeedbackDetailSerializer(),
            status.HTTP_204_NO_CONTENT: {},
            status.HTTP_400_BAD_REQUEST: {},
            status.HTTP_404_NOT_FOUND: {},
            **BASE_ERRORS,
        },
    ),
}

BRAND_SCHEMA = {
    "list": extend_schema(
        tags=[
            "brands",
        ],
        summary=_("list all brands (simple view)"),
        responses={status.HTTP_200_OK: BrandSimpleSerializer(many=True), **BASE_ERRORS},
    ),
    "retrieve": extend_schema(
        tags=[
            "brands",
        ],
        summary=_("retrieve a single brand (detailed view)"),
        parameters=[
            OpenApiParameter(
                name="lookup_value",
                location="path",
                description=_("Brand UUID or slug"),
                type=OpenApiTypes.STR,
            ),
        ],
        responses={status.HTTP_200_OK: BrandDetailSerializer(), **BASE_ERRORS},
    ),
    "create": extend_schema(
        tags=[
            "brands",
        ],
        summary=_("create a brand"),
        responses={status.HTTP_201_CREATED: BrandDetailSerializer(), **BASE_ERRORS},
    ),
    "destroy": extend_schema(
        tags=[
            "brands",
        ],
        summary=_("delete a brand"),
        responses={status.HTTP_204_NO_CONTENT: {}, **BASE_ERRORS},
    ),
    "update": extend_schema(
        tags=[
            "brands",
        ],
        summary=_("rewrite an existing brand saving non-editables"),
        responses={status.HTTP_200_OK: BrandDetailSerializer(), **BASE_ERRORS},
    ),
    "partial_update": extend_schema(
        tags=[
            "brands",
        ],
        summary=_("rewrite some fields of an existing brand saving non-editables"),
        responses={status.HTTP_200_OK: BrandDetailSerializer(), **BASE_ERRORS},
    ),
    "seo_meta": extend_schema(
        tags=[
            "brands",
        ],
        summary=_("SEO Meta snapshot"),
        parameters=[
            OpenApiParameter(
                name="lookup_value",
                location="path",
                description=_("Brand UUID or slug"),
                type=OpenApiTypes.STR,
            ),
        ],
        responses={status.HTTP_200_OK: SeoSnapshotSerializer(), **BASE_ERRORS},
    ),
}

VENDOR_SCHEMA = {
    "list": extend_schema(
        tags=[
            "vendors",
        ],
        summary=_("list all vendors (simple view)"),
        responses={
            status.HTTP_200_OK: VendorSimpleSerializer(many=True),
            **BASE_ERRORS,
        },
    ),
    "retrieve": extend_schema(
        tags=[
            "vendors",
        ],
        summary=_("retrieve a single vendor (detailed view)"),
        responses={status.HTTP_200_OK: VendorDetailSerializer(), **BASE_ERRORS},
    ),
    "create": extend_schema(
        tags=[
            "vendors",
        ],
        summary=_("create a vendor"),
        responses={status.HTTP_201_CREATED: VendorDetailSerializer(), **BASE_ERRORS},
    ),
    "destroy": extend_schema(
        tags=[
            "vendors",
        ],
        summary=_("delete a vendor"),
        responses={status.HTTP_204_NO_CONTENT: {}, **BASE_ERRORS},
    ),
    "update": extend_schema(
        tags=[
            "vendors",
        ],
        summary=_("rewrite an existing vendor saving non-editables"),
        responses={status.HTTP_200_OK: VendorDetailSerializer(), **BASE_ERRORS},
    ),
    "partial_update": extend_schema(
        tags=[
            "vendors",
        ],
        summary=_("rewrite some fields of an existing vendor saving non-editables"),
        responses={status.HTTP_200_OK: VendorDetailSerializer(), **BASE_ERRORS},
    ),
}

PRODUCT_IMAGE_SCHEMA = {
    "list": extend_schema(
        tags=[
            "productImages",
        ],
        summary=_("list all product images (simple view)"),
        responses={
            status.HTTP_200_OK: ProductImageSimpleSerializer(many=True),
            **BASE_ERRORS,
        },
    ),
    "retrieve": extend_schema(
        tags=[
            "productImages",
        ],
        summary=_("retrieve a single product image (detailed view)"),
        responses={status.HTTP_200_OK: ProductImageDetailSerializer(), **BASE_ERRORS},
    ),
    "create": extend_schema(
        tags=[
            "productImages",
        ],
        summary=_("create a product image"),
        responses={
            status.HTTP_201_CREATED: ProductImageDetailSerializer(),
            **BASE_ERRORS,
        },
    ),
    "destroy": extend_schema(
        tags=[
            "productImages",
        ],
        summary=_("delete a product image"),
        responses={status.HTTP_204_NO_CONTENT: {}, **BASE_ERRORS},
    ),
    "update": extend_schema(
        tags=[
            "productImages",
        ],
        summary=_("rewrite an existing product image saving non-editables"),
        responses={status.HTTP_200_OK: ProductImageDetailSerializer(), **BASE_ERRORS},
    ),
    "partial_update": extend_schema(
        tags=[
            "productImages",
        ],
        summary=_(
            "rewrite some fields of an existing product image saving non-editables"
        ),
        responses={status.HTTP_200_OK: ProductImageDetailSerializer(), **BASE_ERRORS},
    ),
}

PROMOCODE_SCHEMA = {
    "list": extend_schema(
        tags=[
            "promocodes",
        ],
        summary=_("list all promo codes (simple view)"),
        responses={
            status.HTTP_200_OK: PromoCodeSimpleSerializer(many=True),
            **BASE_ERRORS,
        },
    ),
    "retrieve": extend_schema(
        tags=[
            "promocodes",
        ],
        summary=_("retrieve a single promo code (detailed view)"),
        responses={status.HTTP_200_OK: PromoCodeDetailSerializer(), **BASE_ERRORS},
    ),
    "create": extend_schema(
        tags=[
            "promocodes",
        ],
        summary=_("create a promo code"),
        responses={status.HTTP_201_CREATED: PromoCodeDetailSerializer(), **BASE_ERRORS},
    ),
    "destroy": extend_schema(
        tags=[
            "promocodes",
        ],
        summary=_("delete a promo code"),
        responses={status.HTTP_204_NO_CONTENT: {}, **BASE_ERRORS},
    ),
    "update": extend_schema(
        tags=[
            "promocodes",
        ],
        summary=_("rewrite an existing promo code saving non-editables"),
        responses={status.HTTP_200_OK: PromoCodeDetailSerializer(), **BASE_ERRORS},
    ),
    "partial_update": extend_schema(
        tags=[
            "promocodes",
        ],
        summary=_("rewrite some fields of an existing promo code saving non-editables"),
        responses={status.HTTP_200_OK: PromoCodeDetailSerializer(), **BASE_ERRORS},
    ),
}

PROMOTION_SCHEMA = {
    "list": extend_schema(
        tags=[
            "promotions",
        ],
        summary=_("list all promotions (simple view)"),
        responses={
            status.HTTP_200_OK: PromotionSimpleSerializer(many=True),
            **BASE_ERRORS,
        },
    ),
    "retrieve": extend_schema(
        tags=[
            "promotions",
        ],
        summary=_("retrieve a single promotion (detailed view)"),
        responses={status.HTTP_200_OK: PromotionDetailSerializer(), **BASE_ERRORS},
    ),
    "create": extend_schema(
        tags=[
            "promotions",
        ],
        summary=_("create a promotion"),
        responses={status.HTTP_201_CREATED: PromotionDetailSerializer(), **BASE_ERRORS},
    ),
    "destroy": extend_schema(
        tags=[
            "promotions",
        ],
        summary=_("delete a promotion"),
        responses={status.HTTP_204_NO_CONTENT: {}, **BASE_ERRORS},
    ),
    "update": extend_schema(
        tags=[
            "promotions",
        ],
        summary=_("rewrite an existing promotion saving non-editables"),
        responses={status.HTTP_200_OK: PromotionDetailSerializer(), **BASE_ERRORS},
    ),
    "partial_update": extend_schema(
        tags=[
            "promotions",
        ],
        summary=_("rewrite some fields of an existing promotion saving non-editables"),
        responses={status.HTTP_200_OK: PromotionDetailSerializer(), **BASE_ERRORS},
    ),
}

STOCK_SCHEMA = {
    "list": extend_schema(
        tags=[
            "stocks",
        ],
        summary=_("list all stocks (simple view)"),
        responses={status.HTTP_200_OK: StockSimpleSerializer(many=True), **BASE_ERRORS},
    ),
    "retrieve": extend_schema(
        tags=[
            "stocks",
        ],
        summary=_("retrieve a single stock (detailed view)"),
        responses={status.HTTP_200_OK: StockDetailSerializer(), **BASE_ERRORS},
    ),
    "create": extend_schema(
        tags=[
            "stocks",
        ],
        summary=_("create a stock record"),
        responses={status.HTTP_201_CREATED: StockDetailSerializer(), **BASE_ERRORS},
    ),
    "destroy": extend_schema(
        tags=[
            "stocks",
        ],
        summary=_("delete a stock record"),
        responses={status.HTTP_204_NO_CONTENT: {}, **BASE_ERRORS},
    ),
    "update": extend_schema(
        tags=[
            "stocks",
        ],
        summary=_("rewrite an existing stock record saving non-editables"),
        responses={status.HTTP_200_OK: StockDetailSerializer(), **BASE_ERRORS},
    ),
    "partial_update": extend_schema(
        tags=[
            "stocks",
        ],
        summary=_(
            "rewrite some fields of an existing stock record saving non-editables"
        ),
        responses={status.HTTP_200_OK: StockDetailSerializer(), **BASE_ERRORS},
    ),
}

PRODUCT_TAG_SCHEMA = {
    "list": extend_schema(
        tags=[
            "productTags",
        ],
        summary=_("list all product tags (simple view)"),
        responses={
            status.HTTP_200_OK: ProductTagSimpleSerializer(many=True),
            **BASE_ERRORS,
        },
    ),
    "retrieve": extend_schema(
        tags=[
            "productTags",
        ],
        summary=_("retrieve a single product tag (detailed view)"),
        responses={status.HTTP_200_OK: ProductTagDetailSerializer(), **BASE_ERRORS},
    ),
    "create": extend_schema(
        tags=[
            "productTags",
        ],
        summary=_("create a product tag"),
        responses={
            status.HTTP_201_CREATED: ProductTagDetailSerializer(),
            **BASE_ERRORS,
        },
    ),
    "destroy": extend_schema(
        tags=[
            "productTags",
        ],
        summary=_("delete a product tag"),
        responses={status.HTTP_204_NO_CONTENT: {}, **BASE_ERRORS},
    ),
    "update": extend_schema(
        tags=[
            "productTags",
        ],
        summary=_("rewrite an existing product tag saving non-editables"),
        responses={status.HTTP_200_OK: ProductTagDetailSerializer(), **BASE_ERRORS},
    ),
    "partial_update": extend_schema(
        tags=[
            "productTags",
        ],
        summary=_(
            "rewrite some fields of an existing product tag saving non-editables"
        ),
        responses={status.HTTP_200_OK: ProductTagDetailSerializer(), **BASE_ERRORS},
    ),
}
