-module(storefront@products). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/storefront/products.gleam"). -export([product_option_decoder/0, product_to_json/1, product_decoder/0, products_decoder/0, reshape_product/2, reshape_products/1]). -export_type([product_option/0, products/0, product/0, shopify_product/0, shopify_collection/0]). -type product_option() :: {product_option, binary(), binary(), list(binary())}. -type products() :: {products, list(product())}. -type product() :: {product, binary(), binary(), boolean(), binary(), binary(), binary(), storefront@utils:price_range(), storefront@utils:image(), storefront@utils:seo(), list(binary()), binary(), list(storefront@utils:product_variant()), list(storefront@utils:image())}. -type shopify_product() :: {shopify_product, binary(), binary(), boolean(), binary(), binary(), binary(), storefront@utils:price_range(), storefront@utils:connection(storefront@utils:product_variant()), storefront@utils:image(), storefront@utils:connection(storefront@utils:image()), storefront@utils:seo(), list(binary()), binary()}. -type shopify_collection() :: {shopify_collection, binary(), binary(), binary(), storefront@utils:seo(), binary()}. -file("src/storefront/products.gleam", 19). -spec product_option_decoder() -> gleam@dynamic@decode:decoder(product_option()). product_option_decoder() -> gleam@dynamic@decode:field( <<"id"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Id) -> gleam@dynamic@decode:field( <<"name"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Name) -> gleam@dynamic@decode:field( <<"values"/utf8>>, gleam@dynamic@decode:list( {decoder, fun gleam@dynamic@decode:decode_string/1} ), fun(Values) -> gleam@dynamic@decode:success( {product_option, Id, Name, Values} ) end ) end ) end ). -file("src/storefront/products.gleam", 53). -spec product_to_json(product()) -> gleam@json:json(). product_to_json(Product) -> {product, Id, Handle, Available_for_sale, Title, Description, Description_html, Price_range, Featured_image, Seo, Tags, Updated_at, Variants, Images} = Product, gleam@json:object( [{<<"id"/utf8>>, gleam@json:string(Id)}, {<<"handle"/utf8>>, gleam@json:string(Handle)}, {<<"availableForSale"/utf8>>, gleam@json:bool(Available_for_sale)}, {<<"title"/utf8>>, gleam@json:string(Title)}, {<<"description"/utf8>>, gleam@json:string(Description)}, {<<"descriptionHtml"/utf8>>, gleam@json:string(Description_html)}, {<<"priceRange"/utf8>>, storefront@utils:price_range_to_json(Price_range)}, {<<"featuredImage"/utf8>>, storefront@utils:image_to_json(Featured_image)}, {<<"seo"/utf8>>, storefront@utils:seo_to_json(Seo)}, {<<"tags"/utf8>>, gleam@json:array(Tags, fun gleam@json:string/1)}, {<<"updatedAt"/utf8>>, gleam@json:string(Updated_at)}, {<<"variants"/utf8>>, gleam@json:array( Variants, fun storefront@utils:product_variant_to_json/1 )}, {<<"images"/utf8>>, gleam@json:array(Images, fun storefront@utils:image_to_json/1)}] ). -file("src/storefront/products.gleam", 86). -spec product_decoder() -> gleam@dynamic@decode:decoder(product()). product_decoder() -> gleam@dynamic@decode:field( <<"id"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Id) -> gleam@dynamic@decode:field( <<"handle"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Handle) -> gleam@dynamic@decode:field( <<"available_for_sale"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_bool/1}, fun(Available_for_sale) -> gleam@dynamic@decode:field( <<"title"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Title) -> gleam@dynamic@decode:field( <<"description"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Description) -> gleam@dynamic@decode:field( <<"description_html"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Description_html) -> gleam@dynamic@decode:field( <<"price_range"/utf8>>, storefront@utils:price_range_decoder( ), fun(Price_range) -> gleam@dynamic@decode:field( <<"featured_image"/utf8>>, storefront@utils:image_decoder( ), fun( Featured_image ) -> gleam@dynamic@decode:field( <<"seo"/utf8>>, storefront@utils:seo_decoder( ), fun(Seo) -> gleam@dynamic@decode:field( <<"tags"/utf8>>, gleam@dynamic@decode:list( {decoder, fun gleam@dynamic@decode:decode_string/1} ), fun( Tags ) -> gleam@dynamic@decode:field( <<"updated_at"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun( Updated_at ) -> gleam@dynamic@decode:field( <<"variants"/utf8>>, gleam@dynamic@decode:list( storefront@utils:product_variant_decoder( ) ), fun( Variants ) -> gleam@dynamic@decode:field( <<"images"/utf8>>, gleam@dynamic@decode:list( storefront@utils:image_decoder( ) ), fun( Images ) -> gleam@dynamic@decode:success( {product, Id, Handle, Available_for_sale, Title, Description, Description_html, Price_range, Featured_image, Seo, Tags, Updated_at, Variants, Images} ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ). -file("src/storefront/products.gleam", 30). -spec products_decoder() -> gleam@dynamic@decode:decoder(products()). products_decoder() -> gleam@dynamic@decode:field( <<"products"/utf8>>, gleam@dynamic@decode:list(product_decoder()), fun(Products) -> gleam@dynamic@decode:success({products, Products}) end ). -file("src/storefront/products.gleam", 150). -spec reshape_product(shopify_product(), boolean()) -> product(). reshape_product(Product, Filter_hidden_products) -> Result = begin Is_hidden = gleam@list:contains( erlang:element(13, Product), <<"gleam-frontend-hidden"/utf8>> ), case Filter_hidden_products andalso Is_hidden of true -> none; false -> Reshaped_image = storefront@utils:reshape_images( erlang:element(11, Product), erlang:element(5, Product) ), Reshaped_variants = storefront@utils:remove_edges_and_nodes( erlang:element(9, Product) ), {some, {product, erlang:element(2, Product), erlang:element(3, Product), erlang:element(4, Product), erlang:element(5, Product), erlang:element(6, Product), erlang:element(7, Product), erlang:element(8, Product), erlang:element(10, Product), erlang:element(12, Product), erlang:element(13, Product), erlang:element(14, Product), Reshaped_variants, Reshaped_image}} end end, Reshaped_image@1 = storefront@utils:reshape_images( erlang:element(11, Product), erlang:element(5, Product) ), Reshaped_variants@1 = storefront@utils:remove_edges_and_nodes( erlang:element(9, Product) ), gleam@option:unwrap( Result, {product, erlang:element(2, Product), erlang:element(3, Product), erlang:element(4, Product), erlang:element(5, Product), erlang:element(6, Product), erlang:element(7, Product), erlang:element(8, Product), erlang:element(10, Product), erlang:element(12, Product), erlang:element(13, Product), erlang:element(14, Product), Reshaped_variants@1, Reshaped_image@1} ). -file("src/storefront/products.gleam", 201). -spec reshape_products(list(shopify_product())) -> list(product()). reshape_products(Products) -> gleam@list:map(Products, fun(Product) -> reshape_product(Product, true) end).