import { expect } from 'chai';

export function checkSuccessResponse(response, withData = true) {
    if (response.code != 0) {
        console.log('checkSuccessResponse info:', JSON.stringify(response))
    }
    expect(response).to.be.an('object');
    expect(response.code).equal(0);
    if (withData) {
        expect(response.data).to.be.an('object');
    }
}

export function checkDisplayItems(items) {
    expect(items).to.be.an('array');
    items.forEach(item => {
        expect(item.id).to.be.a('number');
        expect(item.count).to.be.a('number');
    })
}

export function checkHero(heroes) {
    expect(heroes).to.be.an('array');
    heroes.forEach(hero => {
        expect(hero.seqId).to.be.a('number');
        expect(hero.hid).to.be.a('number');
        expect(hero.hName).to.be.a('string');
        expect(hero.lv).to.be.a('number');
        expect(hero.exp).to.be.a('number');
        expect(hero.star).to.be.a('number');
        expect(hero.starStage).to.be.a('number');
        expect(hero.colorStar).to.be.a('number');
        expect(hero.colorStarStage).to.be.a('number');
        expect(hero.quality).to.be.a('number');
        expect(hero.job).to.be.a('number');
        expect(hero.jobStage).to.be.a('number');
        expect(hero.connections).to.be.an('array');
        hero.connections.forEach(connection => {
            expect(connection.shipId).to.be.a('number');
            expect(connection.level).to.be.a('number');
        });
        expect(hero.favour).to.be.a('number');
        expect(hero.favourLv).to.be.a('number');
        expect(hero.connections).to.be.an('array');
        hero.skins.forEach(skin => {
            expect(skin.id).to.be.a('number');
            expect(skin.enable).to.be.a('boolean');
        });
    })
}

export function addItem(pinusClient, id, count, cb) {
    pinusClient.request('role.heroHandler.addItem', { id, count }, res => {
        checkSuccessResponse(res);
        cb(res);
    });
}