import apollo from "../../lib/apollo.js";

// async function GetProduct(token="", start = 0) {
// 	var res = await apollo.query(
// 		`
//     query($start: Int!) {
//       products(limit:1,start:$start)
//       {
//         id
//         name
//         price
//         description
//         img{
//           url
//         }
//         business_partner
//         {
//           name
//         }
//       }
//     }`,
// 		token,
//     {
//       start: start,
//     }
// 	);
// 	return res;
// }

async function GetDetailProduct(id, token="") {
	var res = await apollo.query(
		`
    query($input: ID!){
      products(where:{id:$input})
      {
        name
        price
        description
        img{
          url
        }
        business_partner
        {
          name
        }
        overview
        specification
        accessories
        film{
          url
        }
        stock
      }
    }	`,
		token, 
    {	
      "input": id
    }
	);
	return res;
}

async function GetProductYamaha(token="") {
	var res = await apollo.query(
		`
    query {
      products(where: {business_partner: "1"})
      {
        id
        name
        description
        price
        img{
          url
        }
        business_partner
        {
          name
        }
        overview
        specification
        accessories
        film{
          url
        }
        stock
      }
    }`,
		token
	);
	return res;
}

async function GetProductSuzuki(token="") {
	var res = await apollo.query(
		`
    query {
      products(where: {business_partner: "2"})
      {
        id
        name
        description
        price
        img{
          url
        }
        business_partner
        {
          name
        }
        overview
        specification
        accessories
        film{
          url
        }
        stock
      }
    }`,
		token
	);
	return res;
}

async function GetProductHonda(token="") {
	var res = await apollo.query(
		`
    query {
      products(where: {business_partner: "3"})
      {
        id
        name
        description
        price
        img{
          url
        }
        business_partner
        {
          name
        }
        overview
        specification
        accessories
        film{
          url
        }
        stock
      }
    }`,
		token
	);
	return res;
}

async function GetProductHino(token="") {
	var res = await apollo.query(
		`
    query {
      products(where: {business_partner: "4"})
      {
        id
        name
        description
        price
        img{
          url
        }
        business_partner
        {
          name
        }
        overview
        specification
        accessories
        film{
          url
        }
        stock
      }
    }`,
		token
	);
	return res;
}

async function GetProductMercedes(token="") {
	var res = await apollo.query(
		`
    query {
      products(where: {business_partner: "5"})
      {
        id
        name
        description
        price
        img{
          url
        }
        business_partner
        {
          name
        }
        overview
        specification
        accessories
        film{
          url
        }
        stock
      }
    }`,
		token
	);
	return res;
}

async function GetProductBPR(token="") {
	var res = await apollo.query(
		`
    query {
      products(where: {business_partner: "6"})
      {
        id
        name
        description
        price
        img{
          url
        }
        business_partner
        {
          name
        }
        overview
        specification
        accessories
        film{
          url
        }
        stock
      }
    }`,
		token
	);
	return res;
}

async function GetProductEmilia(token="") {
	var res = await apollo.query(
		`
    query {
      products(where: {business_partner: "8"})
      {
        id
        name
        description
        price
        img{
          url
        }
        business_partner
        {
          name
        }
        overview
        specification
        accessories
        film{
          url
        }
        stock
      }
    }`,
		token
	);
	return res;
}

async function GetProductHomes(token="") {
	var res = await apollo.query(
		`
    query {
      products(where: {business_partner: "9"})
      {
        id
        name
        description
        price
        img{
          url
        }
        business_partner
        {
          name
        }
        overview
        specification
        accessories
        film{
          url
        }
        stock
      }
    }`,
		token
	);
	return res;
}

module.exports = {
	// GetProduct: GetProduct,
  GetDetailProduct:GetDetailProduct,
  GetProductYamaha:GetProductYamaha,
  GetProductSuzuki:GetProductSuzuki,
  GetProductHonda:GetProductHonda,
  GetProductHino:GetProductHino,
  GetProductMercedes:GetProductMercedes,
  GetProductBPR:GetProductBPR,
  GetProductEmilia:GetProductEmilia,
  GetProductHomes:GetProductHomes,
};