import {GetDataByPath, PostDataByPath, PutDataByPath, ResponseData} from './api.ts';

export class Messages {
    Sender: string;
    BoughtItem: string;
    BoughtDino: string;
    BoughtBeacon: string;
    BoughtExp: string;
    ReceivedPoints: string;
    HavePoints: string;
    NoPoints: string;
    WrongId: string;
    NoPermissionsKit: string;
    CantBuyKit: string;
    BoughtKit: string;
    AvailableKits: string;
    NoKits: string;
    KitsLeft: string;
    NoKitsLeft: string;
    CantGivePoints: string;
    RidingDino: string;
    SentPoints: string;
    GotPoints: string;
    NoPlayer: string;
    FoundMorePlayers: string;
    BuyUsage: string;
    ShopUsage: string;
    KitUsage: string;
    BuyKitUsage: string;
    TradeUsage: string;
    PointsCmd: string;
    TradeCmd: string;
    BuyCmd: string;
    ShopCmd: string;
    KitCmd: string;
    BuyKitCmd: string;
    SellCmd: string;
    ShopSellCmd: string;
    SellUsage: string;
    NotEnoughItems: string;
    SoldItems: string;
    BadLevel: string;
    KitsListPrice: string;
    KitsListFormat: string;
    StoreListDino: string;
    StoreListItem: string;
    StoreListFormat: string;
    OnlyOnSpawnKit: string;
    HelpCmd: string;
    ShopMessage: string;
    HelpMessage: string;
    RefundError: string;
    ShopFindCmd: string;
    ShopFindUsage: string;
    ShopFindNotFound: string;
    ShopFindTooManyResults: string;
    NoPermissionsStore: string;

    constructor() {
        this.Sender = "";
        this.BoughtItem = "";
        this.BoughtDino = "";
        this.BoughtBeacon = "";
        this.BoughtExp = "";
        this.ReceivedPoints = "";
        this.HavePoints = "";
        this.NoPoints = "";
        this.WrongId = "";
        this.NoPermissionsKit = "";
        this.CantBuyKit = "";
        this.BoughtKit = "";
        this.AvailableKits = "";
        this.NoKits = "";
        this.KitsLeft = "";
        this.NoKitsLeft = "";
        this.CantGivePoints = "";
        this.RidingDino = "";
        this.SentPoints = "";
        this.GotPoints = "";
        this.NoPlayer = "";
        this.FoundMorePlayers = "";
        this.BuyUsage = "";
        this.ShopUsage = "";
        this.KitUsage = "";
        this.BuyKitUsage = "";
        this.TradeUsage = "";
        this.PointsCmd = "";
        this.TradeCmd = "";
        this.BuyCmd = "";
        this.ShopCmd = "";
        this.KitCmd = "";
        this.BuyKitCmd = "";
        this.SellCmd = "";
        this.ShopSellCmd = "";
        this.SellUsage = "";
        this.NotEnoughItems = "";
        this.SoldItems = "";
        this.BadLevel = "";
        this.KitsListPrice = "";
        this.KitsListFormat = "";
        this.StoreListDino = "";
        this.StoreListItem = "";
        this.StoreListFormat = "";
        this.OnlyOnSpawnKit = "";
        this.HelpCmd = "";
        this.ShopMessage = "";
        this.HelpMessage = "";
        this.RefundError = "";
        this.ShopFindCmd = "";
        this.ShopFindUsage = "";
        this.ShopFindNotFound = "";
        this.ShopFindTooManyResults = "";
        this.NoPermissionsStore = "";
    }
}

//获取配置文件
export function GetArkConfig(): Promise<ResponseData<Messages>> {
    return GetDataByPath("/ark/messages", {}, true) as Promise<ResponseData<Messages>>;
}

export class General {
    Discord: Discord
    TimedPointsReward: TimedPointsReward
    UseOriginalTradeCommandWithUI: boolean
    ItemsPerPage: number
    ShopDisplayTime: number
    ShopTextSize: number
    DbPathOverride: string
    DefaultKit: string
    GiveDinosInCryopods: boolean
    UseSoulTraps: boolean
    CryoLimitedTime: boolean

    static Create(): General {
        return new General(Discord.Create(), TimedPointsReward.Create(), false, 0, 0, 0, "", "", false, false, false);
    }

    constructor(Discord: Discord, TimedPointsReward: TimedPointsReward, UseOriginalTradeCommandWithUI: boolean, ItemsPerPage: number, ShopDisplayTime: number, ShopTextSize: number, DbPathOverride: string, DefaultKit: string, GiveDinosInCryopods: boolean, UseSoulTraps: boolean, CryoLimitedTime: boolean) {
        this.Discord = Discord;
        this.TimedPointsReward = TimedPointsReward;
        this.UseOriginalTradeCommandWithUI = UseOriginalTradeCommandWithUI;
        this.ItemsPerPage = ItemsPerPage;
        this.ShopDisplayTime = ShopDisplayTime;
        this.ShopTextSize = ShopTextSize;
        this.DbPathOverride = DbPathOverride;
        this.DefaultKit = DefaultKit;
        this.GiveDinosInCryopods = GiveDinosInCryopods;
        this.UseSoulTraps = UseSoulTraps;
        this.CryoLimitedTime = CryoLimitedTime;
    }
}

export class Discord {
    Enabled: boolean     //启用
    SenderName: string  //发件人
    URL: string         //地址

    static Create(): Discord {
        return new Discord(false, "", "");
    }

    constructor(Enabled: boolean, SenderName: string, URL: string) {
        this.Enabled = Enabled;
        this.SenderName = SenderName;
        this.URL = URL;
    }
}


export class TimedPointsReward {
    Enabled: boolean
    Interval: number
    StackRewards: boolean
    Groups: Map<string, TimedPointsRewardAmount>

    static Create(): TimedPointsReward {
        return new TimedPointsReward(false, 0, false, new Map<string, TimedPointsRewardAmount>());
    }

    constructor(Enabled: boolean, Interval: number, StackRewards: boolean, Groups: Map<string, TimedPointsRewardAmount>) {
        this.Enabled = Enabled;
        this.Interval = Interval;
        this.StackRewards = StackRewards;
        this.Groups = Groups;
    }
}

export class TimedPointsRewardAmount {
    Amount: number

    constructor(amount: number) {
        this.Amount = amount;
    }
}

export class Group {
    name: string;
    amount: number;

    constructor(name: string, amount: number) {
        this.name = name;
        this.amount = amount;
    }
}

export function GetTimedPointsReward(): Promise<ResponseData<TimedPointsReward>> {
    return GetDataByPath("/ark/timedPointsReward", {}, true) as Promise<ResponseData<TimedPointsReward>>;
}

export function SaveGroup(group: Group) {
    return PostDataByPath("/ark/timedPointsReward/group", group, true)
}

export function UpdateGroup(oldGroup: Group, newGroup: Group) {
    return PutDataByPath("/ark/timedPointsReward/group", {
        oldGroup: oldGroup, newGroup: newGroup
    }, true)
}

export function GetGeneral(): Promise<ResponseData<General>> {
    return GetDataByPath("/ark/general", {}, true) as Promise<ResponseData<General>>;
}

export function UpdateGeneral(general: General) {
    return PutDataByPath("/ark/general", general, true)
}

//礼包
export class Kit {
    Name: string
    DefaultAmount: number
    Price: number
    Description: string
    Permissions: string
    Dinos: Dino[]
    Items: Item[]

    constructor(Name: string, DefaultAmount: number, Price: number, Description: string, Permissions: string, Dinos: Dino[], Items: Item[]) {
        this.Name = Name;
        this.DefaultAmount = DefaultAmount;
        this.Price = Price;
        this.Description = Description;
        this.Permissions = Permissions;
        this.Dinos = Dinos;
        this.Items = Items;
    }
}

export class Dino {
    Level: number
    Neutered: boolean
    Blueprint: string

    constructor(Level: number, Neutered: boolean, Blueprint: string) {
        this.Level = Level;
        this.Neutered = Neutered;
        this.Blueprint = Blueprint;
    }
}

export class Item {
    Amount: number
    Blueprint: string
    Fixed: boolean
    ForceBlueprint: boolean
    Quality: number


    constructor(Amount: number, Blueprint: string, Fixed: boolean, ForceBlueprint: boolean, Quality: number) {
        this.Amount = Amount;
        this.Blueprint = Blueprint;
        this.Fixed = Fixed;
        this.ForceBlueprint = ForceBlueprint;
        this.Quality = Quality;
    }
}

export function GetKits() {
    return GetDataByPath("/ark/kit", {}, true) as Promise<ResponseData<Kit[]>>;
}

export function SaveKit(kit: Kit) {
    return PostDataByPath("/ark/kit", kit, true)
}

export function UpdateKit(oldKit: Kit, newKit: Kit) {
    return PutDataByPath("/ark/kit", {
        oldKit: oldKit, newKit: newKit
    }, true)
}

export function DeleteKit(kitName: string) {
    return PutDataByPath("/ark/kit", {kitName: kitName}, true)
}

export class ShopItem {
    Description: string
    Items: Item[]
    Price: number
    Type: string

    constructor(Description: string, Items: Item[], Price: number, Type: string) {
        this.Description = Description;
        this.Items = Items;
        this.Price = Price;
        this.Type = Type;
    }
}
//
// export function GetShopItems() {
//     return GetDataByPath("/ark/shopItems", {}, true) as Promise<ResponseData<ShopItem[]>>;
// }
//
// export function SaveShopItem(shopItem: ShopItem) {
//     return PutDataByPath("/ark/shopItems", shopItem, true)
// }
//
// export function UpdateShopItem(oldShopItem: ShopItem, newShopItem: ShopItem) {
//     return PutDataByPath("/ark/shopItems", {
//         oldShopItem: oldShopItem, newShopItem: newShopItem
//     }, true)
// }
//
// export function DeleteShopItem(shopItemName: string) {
//     return PutDataByPath("/ark/shopItems", {shopItemName: shopItemName}, true)
// }


// SellItem 允许玩家出售物资，以换取积分
export class SellItem {
    Type: string
    Description: string
    Price: number
    Amount: number
    Blueprint: string

    constructor(Type: string, Description: string, Price: number, Amount: number, Blueprint: string) {
        this.Type = Type;
        this.Description = Description;
        this.Price = Price;
        this.Amount = Amount;
        this.Blueprint = Blueprint;
    }
}

export function GetSellItems() {
    return GetDataByPath("/ark/sellItems", {}, true) as Promise<ResponseData<SellItem[]>>;
}

export function SaveSellItem(sellItem: SellItem) {
    return PostDataByPath("/ark/sellItems", sellItem, true)
}

export function UpdateSellItem(oldSellItem: SellItem, newSellItem: SellItem) {
    return PutDataByPath("/ark/sellItems", {
        oldSellItem: oldSellItem, newSellItem: newSellItem
    }, true)
}

export function DeleteSellItem(sellItemName: string) {
    return PutDataByPath("/ark/sellItems", {sellItemName: sellItemName}, true)
}

export class BaseData<T> {
    Name: string
    data: T

    constructor(Name: string, data: T) {
        this.Name = Name;
        this.data = data;
    }
}