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

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

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

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

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

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

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

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

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

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

module.exports = {
    GetApparel:GetApparel,
    GetApparel46Asia:GetApparel46Asia,
    GetApparelBasic:GetApparelBasic,
    GetApparelMerchandise:GetApparelMerchandise,
    GetApparelMaxi:GetApparelMaxi,
    GetApparelRainSuit:GetApparelRainSuit,
    GetApparelMotoGP:GetApparelMotoGP,
    GetApparelOffRoad:GetApparelOffRoad,
    GetDetailApparel:GetDetailApparel,
};