import {
  GenerateWaywardLinkBody,
  GetProductsQuery,
  GetProductsResponse,
  GenerateWaywardLinkSuccess,
} from "@komi-app/affiliate-sdk";
import { getAffiliateService } from "services";
import { Maybe } from "types/utilities";

export const fetchProductsFromWayward = async (
  query: GetProductsQuery
): Promise<Maybe<GetProductsResponse>> => {
  try {
    const response = await getAffiliateService().getWaywardProducts(query);
    return response;
  } catch (error) {
    console.error("Error fetching products from service: ", error);
    throw error;
  }
};

export const generateWaywardLink = async (
  payload: GenerateWaywardLinkBody
): Promise<Maybe<GenerateWaywardLinkSuccess>> => {
  try {
    const response = await getAffiliateService().generateWaywardLink(payload);
    return response;
  } catch (error) {
    console.error("Error fetching products from service: ", error);
    throw error;
  }
};

/* This static list of categories is from wayward docs. 
Since they don't have any API yet we are initialising as const.
Ref : https://documenter.getpostman.com/view/5682126/2sA358e6N5#a0da0cd3-7f95-458c-8dce-fba20b2b15e6
*/
export const WaywardCategories = [
  { name: "Appliances", key: "93377ae4-1eca-49e4-878c-a9feb6d3631a" },
  {
    name: "Arts, Crafts & Sewing",
    key: "c3e52637-1bb4-4c5a-ab2f-910fa083c871",
  },
  { name: "Baby Products", key: "b49a85da-9e1e-41a5-bcb8-9bc7ca5d3cd6" },
  {
    name: "Beauty & Personal Care",
    key: "c6319219-5ca4-48c3-884b-8ef9d65ffe83",
  },
  {
    name: "Clothing, Shoes & Jewelry",
    key: "5efa4d82-3e82-4487-b604-64126e5238c4",
  },
  { name: "Electronics", key: "60907e17-592c-4d0a-af53-34c97c0e2930" },
  { name: "Health & Household", key: "47174d9d-eefb-4ae3-a21c-def6ba03ac54" },
  { name: "Home & Kitchen", key: "498d94a6-6213-4cf6-a924-18aeef129f1b" },
  { name: "Musical Instruments", key: "8c0be332-a061-4ba3-896a-f69e9eb17d0e" },
  { name: "Office Products", key: "0fd36375-c373-434a-8ffa-868c3a7de144" },
  { name: "Patio, Lawn & Garden", key: "be9aae97-ca4f-4d85-9881-8e02ce78668d" },
  { name: "Pet Supplies", key: "8d92e1ad-0223-4c00-b5e2-b33f6c6d221d" },
  { name: "Sports & Outdoors", key: "4bc6c107-5a4e-4153-92a2-76fbe99ecc98" },
  {
    name: "Tools & Home Improvement",
    key: "5e80a671-0161-40ea-a0f5-34830bab5663",
  },
  { name: "Toys & Games", key: "fded1972-630b-4d55-8b16-ec5caa713746" },
];
