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

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

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

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

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

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

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

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

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


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

module.exports = {
    GetHelmetRConcepts:GetHelmetRConcepts,
    GetHelmetMTX:GetHelmetMTX,
    GetHelmetExtreme:GetHelmetExtreme,
    GetHelmetRanger:GetHelmetRanger,
    GetHelmetFighter:GetHelmetFighter,
    GetHelmetSwirl:GetHelmetSwirl,
    GetHelmetClassic:GetHelmetClassic,
    GetHelmetUno:GetHelmetUno,
    GetDetailHelmet:GetDetailHelmet,
};