#ifndef _CAFF_H_
#define _CAFF_H_
#include <stdio.h>
#include <stdint.h>

#include "ciff.h"

typedef struct {
    char magic[4];  // The magic string 'CAFF'
    uint64_t header_size;  // The size of the header
    uint64_t num_anim;  // The number of animated CIFFs
} CAFF_Header;

typedef struct {
    uint16_t year;  // Year of creation
    uint8_t month;  // Month of creation
    uint8_t day;  // Day of creation
    uint8_t hour;  // Hour of creation
    uint8_t minute;  // Minute of creation
    uint64_t creator_len;  // Length of the creator field
    char* creator;  // The creator of the CAFF file
} CAFF_Credits;

typedef struct {
    uint64_t duration;  // Duration of the animation in milliseconds
    CIFF* ciff;  // The CIFF image
} CAFF_Animation;

typedef struct {
  CAFF_Animation *array;
  size_t length;
  size_t size;
} CAFF_Animation_List;

typedef struct {
    CAFF_Header* header;  // The CAFF header
    CAFF_Credits* credits;  // The CAFF credits
    CAFF_Animation_List animations;  // The CAFF animations
    uint64_t bytes_read;
} CAFF;
CAFF* caff_parse_file(const char* filename);
CAFF_Header* read_header(FILE* file);
CAFF_Credits* read_credits(FILE* file);
CAFF_Animation* read_animation(FILE* file);
void caff_free(CAFF* caff);

#endif