Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ default.profraw
junit-swift-testing.xml

# Claude
.claude/settings.local.json
.claude/settings.local.json

# Git worktrees
.worktrees/
24 changes: 24 additions & 0 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions Sources/TMDb/Domain/Models/AccountStates.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// AccountStates.swift
// TMDb
//
// Copyright © 2026 Adam Young.
//

import Foundation

///
/// A model representing a user's account states for media.
///
public struct AccountStates: Codable, Equatable, Hashable, Sendable {

///
/// Media identifier.
///
public let id: Int

///
/// Is the media in the user's favorites.
///
public let isFavourite: Bool

///
/// The user's rating for the media.
///
public let rating: Double?

///
/// Is the media in the user's watchlist.
///
public let isInWatchlist: Bool

///
/// Creates an account states object.
///
/// - Parameters:
/// - id: Media identifier.
/// - isFavourite: Is the media in the user's favorites.
/// - rating: The user's rating for the media.
/// - isInWatchlist: Is the media in the user's watchlist.
///
public init(id: Int, isFavourite: Bool, rating: Double? = nil, isInWatchlist: Bool) {
self.id = id
self.isFavourite = isFavourite
self.rating = rating
self.isInWatchlist = isInWatchlist
}

}

extension AccountStates {

private enum CodingKeys: String, CodingKey {
case id
case isFavourite = "favorite"
case rating = "rated"
case isInWatchlist = "watchlist"
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

self.id = try container.decode(Int.self, forKey: .id)
self.isFavourite = try container.decode(Bool.self, forKey: .isFavourite)
self.isInWatchlist = try container.decode(Bool.self, forKey: .isInWatchlist)

// rating can be false (boolean) or a number (double)
if let ratingValue = try? container.decode(Double.self, forKey: .rating) {
self.rating = ratingValue
} else {
self.rating = nil
}
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(id, forKey: .id)
try container.encode(isFavourite, forKey: .isFavourite)
try container.encode(isInWatchlist, forKey: .isInWatchlist)

if let rating {
try container.encode(rating, forKey: .rating)
} else {
try container.encode(false, forKey: .rating)
}
}

}
54 changes: 54 additions & 0 deletions Sources/TMDb/Domain/Models/AlternativeTitle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// AlternativeTitle.swift
// TMDb
//
// Copyright © 2026 Adam Young.
//

import Foundation

///
/// A model representing an alternative title.
///
public struct AlternativeTitle: Codable, Equatable, Hashable, Sendable {

///
/// ISO 3166-1 country code.
///
public let countryCode: String

///
/// Title.
///
public let title: String

///
/// Type of alternative title.
///
public let type: String?

///
/// Creates an alternative title object.
///
/// - Parameters:
/// - countryCode: ISO 3166-1 country code.
/// - title: Title.
/// - type: Type of alternative title.
///
public init(countryCode: String, title: String, type: String? = nil) {
self.countryCode = countryCode
self.title = title
self.type = type
}

}

extension AlternativeTitle {

private enum CodingKeys: String, CodingKey {
case countryCode = "iso31661"
case title
case type
}

}
46 changes: 46 additions & 0 deletions Sources/TMDb/Domain/Models/AlternativeTitleCollection.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// AlternativeTitleCollection.swift
// TMDb
//
// Copyright © 2026 Adam Young.
//

import Foundation

///
/// A model representing a collection of alternative titles.
///
public struct AlternativeTitleCollection: Codable, Equatable, Hashable, Sendable {

///
/// Media identifier.
///
public let id: Int

///
/// Alternative titles.
///
public let titles: [AlternativeTitle]

///
/// Creates an alternative title collection object.
///
/// - Parameters:
/// - id: Media identifier.
/// - titles: Alternative titles.
///
public init(id: Int, titles: [AlternativeTitle]) {
self.id = id
self.titles = titles
}

}

extension AlternativeTitleCollection {

private enum CodingKeys: String, CodingKey {
case id
case titles = "results"
}

}
Loading
Loading