import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { shareReplay } from 'rxjs/operators';

import { HWGuildData, HWGuildWarSlots, HWWeekStat } from '@models';

export interface HWGuildStatistics {
    stat: (HWWeekStat & { id: string })[];
}

@Injectable({ providedIn: 'root' })
export class HWDataService {
    private _http = inject(HttpClient);

    readonly guildData$: Observable<HWGuildData> = this._http
        .get<HWGuildData>('/assets/files-data/hw-guild-data.json')
        .pipe(shareReplay(1));

    readonly guildStatistics$: Observable<HWGuildStatistics> = this._http
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        .get<HWGuildStatistics>('/assets/files-data/hw-guild-statistics.json')
        .pipe(shareReplay(1));

    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    readonly guildRaids$: Observable<Record<string, Record<string, any>>> = this._http
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        .get<Record<string, Record<string, any>>>('/assets/files-data/hw-guild-raids.json')
        .pipe(shareReplay(1));

    /* eslint-disable @typescript-eslint/no-explicit-any */
    readonly guildWarData$: Observable<any> = this._http
        .get<any>('/assets/files-data/hw-guild-war.json')
        .pipe(shareReplay(1));

    readonly guildWarInfo$: Observable<any> = this._http
        .get<any>('/assets/files-data/hw-guild-war-info.json')
        .pipe(shareReplay(1));
    /* eslint-enable @typescript-eslint/no-explicit-any */

    readonly guildWarSlots$: Observable<{ slots: HWGuildWarSlots }> = this._http
        .get<{ slots: HWGuildWarSlots }>('/assets/files-data/hw-guild-war-slots.json')
        .pipe(shareReplay(1));
}
