import { DependencyContainer } from "tsyringe";

// SPT types
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
import { InitialModLoader } from "@spt-aki/loaders/InitialModLoader";
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
import { ImporterUtil } from "@spt-aki/utils/ImporterUtil";
import { ImageRouter } from "@spt-aki/routers/ImageRouter";
import { CustomTraderAssortData } from "../models/spt/services/CustomTraderAssortData";
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
import { ITraderAssort, ITraderBase } from "@spt-aki/models/eft/common/tables/ITrader";
import { ITraderConfig, UpdateTime } from "@spt-aki/models/spt/config/ITraderConfig";
import { JsonUtil } from "@spt-aki/utils/JsonUtil";
import { Item } from "@spt-aki/models/eft/common/tables/IItem";
import { ILocaleGlobalBase } from "@spt-aki/models/spt/server/ILocaleBase";
import { CustomTraderAssortService } from "@spt-aki/services/CustomTraderAssortService";

class target implements IMod
{

    public preSptLoad(container: DependencyContainer): void {			
    const logger = container.resolve<ILogger>("WinstonLogger");		
    }

    public postDBLoad(container: DependencyContainer)
    {
				
		const databaseServer = container.resolve<DatabaseServer>("DatabaseServer");
		const tables = databaseServer.getTables();
        const ImporterUtil = container.resolve<ImporterUtil>("ImporterUtil");
		const locales = Object.values(tables.locales.global) as ILocaleGlobalBase[];
        const PreSptModLoader = container.resolve<PreSptModLoader>("PreSptModLoader");
		const logger = container.resolve<ILogger>("WinstonLogger");
        const db = ImporterUtil.loadRecursive(`${PreSptModLoader.getModPath("AT-freedom")}db/`);
		const allitems = tables.templates.items;
		
		//添加mod物品的items
		for (const item in db.items) {
			tables.templates.items[item] = db.items[item];
		}
		
		//添加文字说明
        for(const description in db.locales["ATdescription"]){
			tables.locales.global['ch'][description] = db.locales["ATdescription"][description]
		}
		for(const endescription in db.locales["ATdescriptionen"]){
			tables.locales.global['en'][endescription] = db.locales["ATdescriptionen"][endescription]
		}
		//添加物品的跳蚤分类
		for (const ha in db.templates.handbook) {
			tables.templates.handbook.Items.push(db.templates.handbook[ha]);
		}
		
		//枪管增加技能核心配件	
		function peijian(A,B){
			for (const item in tables.templates.items) {
				if (tables.templates.items[item]._props.Slots) {
					for (const slot in tables.templates.items[item]._props.Slots) {
						for (const filter in tables.templates.items[item]._props.Slots[slot]._props.filters[0].Filter) {					
							if (tables.templates.items[item]._props.Slots[slot]._props.filters[0].Filter[filter] === A) {
								tables.templates.items[item]._props.Slots[slot]._props.filters[0].Filter.push(B)}					
						}
					}
				}
			}
		}	
	
	    //添加商人售卖，本框架给的毛商
		for (const newitems in db.traders) {
            for (const item in db.traders[newitems].assort.items) {
                tables.traders[newitems].assort.items.unshift(db.traders[newitems].assort.items[item])
            }

            for (const item in db.traders[newitems].assort.barter_scheme) {
                tables.traders[newitems].assort.barter_scheme[item] =db.traders[newitems].assort.barter_scheme[item]
            }

            for (const item in db.traders[newitems].assort.loyal_level_items) {
                tables.traders[newitems].assort.loyal_level_items[item] = db.traders[newitems].assort.loyal_level_items[item]
            }
        }
		
    }
   

}

module.exports = { mod: new target() }
