import request from '@/utils/request'

export interface MatchLiveStreamOption {
    id?: number | string
    title?: string
    name?: string
    label?: string
    source_name?: string
    quality?: string
    url?: string
    play_url?: string
    play_url_m3u8?: string
    play_url_hd_m3u8?: string
    play_url_flv?: string
    play_url_hd_flv?: string
    default_play_url?: string
    live_url?: string
    source_url?: string
    fetch_status?: string | number
    last_fetch_at?: string | number
    update_time?: string | number
    stream_options?: MatchLiveStreamOption[]
    [key: string]: any
}

export interface MatchLiveLineItem {
    id?: number | string
    title?: string
    name?: string
    label?: string
    live_tag?: string
    source_name?: string
    status?: string | number
    status_text?: string
    status_desc?: string
    update_time?: string | number
    updated_at?: string | number
    source_url?: string
    default_play_url?: string
    play_url_m3u8?: string
    play_url_hd_m3u8?: string
    play_url_flv?: string
    play_url_hd_flv?: string
    play_url?: string
    live_url?: string
    fetch_status?: string | number
    last_fetch_at?: string | number
    stream_options?: MatchLiveStreamOption[]
    [key: string]: any
}

export interface WorldCupLiveCardItem {
    live_id: number
    match_id: number
    title?: string
    source_url?: string
    anchor_name?: string
    anchor_avatar?: string
    room_view_count?: number | string
    room_focus_count?: number | string
    room_notice?: string
    play_url: string
    default_play_url?: string
    stream_options?: MatchLiveStreamOption[]
    fetch_status?: string | number
    last_fetch_at?: string | number
    update_time?: string | number
    id: number
    competition_id?: number
    league_name?: string
    round_name?: string
    stage?: string
    home_team?: string
    home_icon?: string
    home_score?: number
    away_team?: string
    away_icon?: string
    away_score?: number
    status?: number
    match_time?: number
    current_minute?: string
    half_score?: string
    [key: string]: any
}

export interface WorldCupOddsValue {
    label: string
    value: string
}

export interface WorldCupOddsMarket {
    label: string
    line?: string
    values: WorldCupOddsValue[]
}

export interface WorldCupOddsPlatform {
    platform_key: string
    platform_name: string
    show_type: string
    show_type_text: string
    odds_type?: string
    source_match_id?: string
    update_time?: number
    markets: WorldCupOddsMarket[]
}

export interface WorldCupOddsMatchItem {
    id?: number
    match_id?: number
    source_match_ids?: string[]
    league_name?: string
    match_time_text?: string
    match_time?: number
    home_team: string
    home_icon?: string
    home_score?: number
    away_team: string
    away_icon?: string
    away_score?: number
    status?: number
    current_minute?: string
    platforms: WorldCupOddsPlatform[]
    update_time?: number
    [key: string]: any
}

export type MatchLiveCardItem = WorldCupLiveCardItem
export type MatchOddsMatchItem = WorldCupOddsMatchItem

export function getMatchList(data?: Record<string, any>) {
    return request.get({ url: '/match/lists', data: data }, { withToken: false })
}

export function getMatchDetail(data: { id: number }) {
    return request.get({ url: '/match/detail', data: data }, { withToken: false })
}

export function getSportTypes() {
    return request.get({ url: '/match/sportTypes' }, { withToken: false })
}

export function getMatchLeagues(data?: { sport_type?: number }) {
    return request.get({ url: '/match/leagues', data: data }, { withToken: false })
}

export function getMatchLiveText(data: { match_id: number; last_msg_id?: number }) {
    return request.get({ url: '/match/liveText', data: data }, { withToken: false })
}

export function getMatchLineup(data: { match_id: number }) {
    return request.get({ url: '/match/lineup', data: data }, { withToken: false })
}

export function getWorldCupStandings() {
    return request.get({ url: '/match/worldCupStandings' }, { withToken: false })
}

export function getWorldCupRankings(data: { type: 'goals' | 'assists' }) {
    return request.get({ url: '/match/worldCupRankings', data }, { withToken: false })
}

export function getWorldCupSchedule() {
    return request.get({ url: '/match/worldCupSchedule' }, { withToken: false })
}

export function getWorldCupLiveCards() {
    return request.get({ url: '/match/worldCupLiveCards' }, { withToken: false })
}

export function getMatchLiveCards(data?: {
    sport_type?: number
    league_name?: string
}) {
    return request.get({ url: '/match/liveCards', data }, { withToken: false })
}

export function getMatchOdds(data?: {
    sport_type?: number
    league_name?: string
    show_type?: 'live' | 'today' | 'early'
    source_site?: string
    keyword?: string
    home_team?: string
    away_team?: string
    match_date?: string
    include_special?: number
    limit?: number
}) {
    return request.get({ url: '/match/odds', data }, { withToken: false })
}

export function getWorldCupOdds(data?: {
    show_type?: 'live' | 'today' | 'early'
    source_site?: string
    keyword?: string
    include_special?: number
    limit?: number
}) {
    return request.get({ url: '/match/worldCupOdds', data }, { withToken: false })
}
