Football Operations

Core Data Models

Match Model (MatchBasicModel)

// Key properties
match.id: String                           // Unique match identifier
match.homeTeam: TeamBasicModel             // Home team information
match.awayTeam: TeamBasicModel             // Away team information
match.competition: CompetitionBasicModel?  // Competition/league info
match.kickoffAt: Kotlinx_datetimeInstant?  // Match kickoff time
match.status: MatchStatus?                 // Match status
match.scores: MatchScores?                 // Match scores

Team Model (TeamBasicModel)

team.id: String                    // Unique team identifier
team.name: String                  // Team name
team.fullName: String?             // Full team name
team.shortName: String?            // Short team name
team.country: FootballCountryModel? // Team country
team.assets: AssetsModel?          // Team logos/images

Competition Model (CompetitionBasicModel)

competition.id: String                     // Competition identifier
competition.name: String                   // Competition name
competition.country: FootballCountryModel? // Competition country
competition.type: CompetitionType?         // Competition type

Football Operations

Get Matches

do {
    // Create filters (optional)
    let filters = MatchFilters(
        countryIds: nil,
        competitionIds: nil,
        matchIds: nil,
        status: nil,
        teamIds: nil,
        fromDate: todayInstant,
        toDate: nil,
        limit: 50,
        page: nil,
        sortField: nil,
        sortOrder: nil
    )

    // Fetch matches
    let matches = try await sdk.football().getMatches(filters: filters, disableCache: false)?.data

    if let matchArray = matches as? [MatchBasicModel] {
        print("Loaded \(matchArray.count) matches")
        // Handle matches
    }

} catch {
    print("Error fetching matches: \(error.localizedDescription)")
}

Get Teams

do {
    let teams = try await sdk.football().getTeams(filters: nil, disableCache: false)?.data
    if let teamArray = teams as? [TeamBasicModel] {
        // Handle teams
    }
} catch {
    print("Error fetching teams: \(error)")
}

Get Competitions

do {
    let competitions = try await sdk.football().getCompetitions(filters: nil, disableCache: false)
    // Handle competitions array
} catch {
    print("Error fetching competitions: \(error)")
}

Get Players

do {
    let players = try await sdk.football().getPlayers(filters: nil, disableCache: false)?.data
    if let playerArray = players as? [PlayerBasicModel] {
        // Handle players
    }
} catch {
    print("Error fetching players: \(error)")
}

Get Countries

do {
    let countries = try await sdk.football().getCountries(disableCache: false)
    for country in countries {
        print("Country: \(country.name)")
    }
} catch {
    print("Error fetching countries: \(error)")
}

Get Match by ID

do {
    let match = try await sdk.football().getMatchById(id: "fb:m:123", disableCache: false)
    print("Match: \(match.homeTeam.name) vs \(match.awayTeam.name)")
} catch {
    print("Error fetching match: \(error)")
}

Get Team by ID

do {
    let team = try await sdk.football().getTeamById(id: "fb:t:123", disableCache: false)
    print("Team: \(team.name)")
    print("Country: \(team.country?.name ?? "Unknown")")
} catch {
    print("Error fetching team: \(error)")
}

Get Player by ID

do {
    let player = try await sdk.football().getPlayerById(id: "fb:p:123", disableCache: false)
    print("Player: \(player.name)")
    print("Position: \(player.position?.name ?? "Unknown")")
} catch {
    print("Error fetching player: \(error)")
}

Get Competition by ID

do {
    let competition = try await sdk.football().getCompetitionById(id: "competition123", disableCache: false)
    print("Competition: \(competition.name)")
    print("Country: \(competition.country?.name ?? "Unknown")")
} catch {
    print("Error fetching competition: \(error)")
}

Get Next Match for Player

do {
    let nextMatch = try await sdk.football().getNextMatchForPlayer(id: "fb:p:123", disableCache: false)
    if let match = nextMatch {
        print("Next match: \(match.homeTeam.name) vs \(match.awayTeam.name)")
    }
} catch {
    print("Error fetching next match: \(error)")
}

Get Next Match for Team

do {
    let nextMatch = try await sdk.football().getNextMatchForTeam(id: "fb:t:123", disableCache: false)
    if let match = nextMatch {
        print("Next match: \(match.homeTeam.name) vs \(match.awayTeam.name)")
    }
} catch {
    print("Error fetching next match: \(error)")
}

Get Previous Match for Player

do {
    let prevMatch = try await sdk.football().getPrevMatchForPlayer(id: "fb:p:123", disableCache: false)
    if let match = prevMatch {
        print("Previous match: \(match.homeTeam.name) vs \(match.awayTeam.name)")
    }
} catch {
    print("Error fetching previous match: \(error)")
}

Get Previous Match for Team

do {
    let prevMatch = try await sdk.football().getPrevMatchForTeam(id: "fb:t:123", disableCache: false)
    if let match = prevMatch {
        print("Previous match: \(match.homeTeam.name) vs \(match.awayTeam.name)")
    }
} catch {
    print("Error fetching previous match: \(error)")
}

Get Team Form

do {
    let filters = TeamFormFilters(
        limit: 10,
        direction: TeamFormDirection.home
    )

    let teamForm = try await sdk.football().getTeamForm(
        teamId: "fb:t:123",
        filters: filters,
        disableCache: false
    )

    print("Team form: \(teamForm.matches?.count ?? 0) matches")
} catch {
    print("Error fetching team form: \(error)")
}

Get Top Teams

do {
    let topTeams = try await sdk.football().getTopTeams(disableCache: false)
    for team in topTeams {
        print("Top team: \(team.name)")
    }
} catch {
    print("Error fetching top teams: \(error)")
}

Get Top Players

do {
    let topPlayers = try await sdk.football().getTopPlayers(disableCache: false)
    for player in topPlayers {
        print("Top player: \(player.name)")
    }
} catch {
    print("Error fetching top players: \(error)")
}

Get Top Competitions

do {
    let topCompetitions = try await sdk.football().getTopCompetitions(disableCache: false)
    for competition in topCompetitions {
        print("Top competition: \(competition.name)")
    }
} catch {
    print("Error fetching top competitions: \(error)")
}