package dev.photosync.core.provider.immich;

import java.util.List;

/**
 * The slices of the Immich API that PhotoSync actually reads, mirrored as
 * records for Gson.
 *
 * <p>Written against Immich's published OpenAPI document, version 3.1.0. Fields
 * the mod does not use are simply absent -- Gson ignores unknown JSON members,
 * so the smaller this file is, the fewer ways a server upgrade can break us.
 *
 * <p>Two absences are deliberate rather than incidental:
 *
 * <ul>
 *   <li>{@code duration} is not read. It has changed representation between
 *       Immich releases (string, then seconds) and the only thing PhotoSync
 *       would do with it is decorate a badge it already draws from
 *       {@code isImage}.</li>
 *   <li>Boxed types throughout, because every one of these arrays is declared
 *       nullable somewhere in the schema, and an older server that omits one
 *       should degrade rather than throw.</li>
 * </ul>
 */
final class ImmichDtos {

    private ImmichDtos() {
    }

    record ServerAbout(String version) {
    }

    record UserProfile(String name, String email) {
    }

    record AlbumSummary(String id, String albumName, Integer assetCount, String albumThumbnailAssetId) {
    }

    record CreateAlbum(String albumName) {
    }

    /** {@code status} is {@code created} or {@code duplicate}. */
    record AssetMediaResponse(String id, String status) {
    }

    /** Body for {@code PATCH /assets/:id} -- the only field PhotoSync writes. */
    record UpdateAsset(String description) {
    }

    record BulkIds(List<String> ids) {
    }

    record BulkIdResponse(String id, Boolean success, String error) {
    }

    /** {@code timeBucket} is an opaque token; we hand it straight back to the server. */
    record TimeBucket(String timeBucket, Integer count) {
    }

    /**
     * Immich returns a bucket columnwise: one array per attribute, all the same
     * length, indexed in parallel. It is an odd shape for a REST API and a very
     * good one for this use case -- a thousand assets arrive without a thousand
     * repetitions of every key name.
     */
    record BucketAssets(
            List<String> id,
            List<String> fileCreatedAt,
            List<Double> localOffsetHours,
            List<Double> ratio,
            List<String> thumbhash,
            List<Boolean> isImage) {

        int size() {
            return id == null ? 0 : id.size();
        }
    }

    /** The body Immich returns on an error, when it returns one at all. */
    record ApiError(String message, String error, Integer statusCode) {
    }
}
