#ifndef _fencer_asset_h
#define _fencer_asset_h

#include "drop.h"
#include "typeclass_helpers.h"
#include <SDL2/SDL_render.h>

typedef uintptr_t asset_id;

typedef struct {
    asset_id (*const get_id)(void*);
    void (*const set_id)(void*, asset_id);
} IAsset;

typedef struct Asset {
    void* data;
    IAsset const* tc;
    IDrop const* drop;
} Asset;

#define impl_Asset_for(T, get_id_f, set_id_f)\
Asset T##_as_Asset(T* x) {\
    TC_FN_TYPECHECK(asset_id, get_id_f, T*);\
    TC_FN_TYPECHECK(void, set_id_f, T*, asset_id);\
    TC_FN_TYPECHECK(Drop, T##_as_Drop, T*);\
    static IAsset const tc = {\
        .get_id = (asset_id(*const)(void*))      get_id_f,\
        .set_id = (void(*const)(void*,asset_id)) set_id_f,\
    };\
    IDrop const* drop = T##_as_Drop(x).tc;\
    return (Asset){.data=x, .tc=&tc, .drop=drop};\
}

#endif // !_fencer_asset_h
