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

async function GetYGP(filter, token="") {
	var res = await apollo.query(
		`
        query {
            accessories(where: { category: "YGP" ${(filter!="")?`name: "${filter}"`:""}}) {
                id
                name
                price
                img {
                    url
                }
            }
        }`,
		token
	);
	return res;
}

async function GetYamalube(filter, token="") {
	var res = await apollo.query(
		`
        query {
            accessories(where: { category: "Yamalube" ${(filter!="")?`name: "${filter}"`:""}}) {
                id
                name
                price
                img {
                    url
                }
            }
        }`,
		token
	);
	return res;
}

async function GetHelmet(filter, token="") {
	var res = await apollo.query(
		`
        query {
            accessories(where: { category: "Helmet" ${(filter!="")?`name: "${filter}"`:""}}) {
                id
                name
                price
                img {
                    url
                }
            }
        }`,
		token
	);
	return res;
}

async function GetApparel(filter, token="") {
	var res = await apollo.query(
		`
        query {
            accessories(where: { category: "Apparel" ${(filter!="")?`name: "${filter}"`:""}}) {
                id
                name
                price
                img {
                    url
                }
            }
        }`,
		token
	);
	return res;
}

async function GetAccessories(filter, token="") {
	var res = await apollo.query(
		`
        query {
            accessories(where: { category: "Accessories" ${(filter!="")?`name: "${filter}"`:""}}) {
                id
                name
                price
                img {
                    url
                }
            }
        }`,
		token
	);
	return res;
}

async function GetDetailAccessories(id, token="") {
	var res = await apollo.query(
		`
        query($input: ID!){
            accessories(where:{id:$input})
            {
                id
                name
                description
                price
                part_code
                img {
                    url
                }
                img_relate1{
                    url
                }
                img_relate2{
                    url
                }
                img_relate3{
                    url
                }
                stock
            }
        }	`,
            token, 
        {	
        "input": id
        }
	);
	return res;
}

module.exports = {
    GetYGP:GetYGP,
    GetYamalube:GetYamalube,
    GetHelmet:GetHelmet,
    GetApparel:GetApparel,
    GetAccessories:GetAccessories,
    GetDetailAccessories:GetDetailAccessories,
};