import { Column, Entity, getRepository, PrimaryColumn } from 'typeorm';

export type DrawableData = {
    componentId: number;
    drawableId: number;
    texture: number;
    palette?: number;
};

@Entity('appearance_presets')
export class AppearancePresetEntity {
    @PrimaryColumn({ type: 'varchar', length: 32, nullable: false }) name: string;
    @Column({ type: 'int', nullable: false }) character_id: number;
    @Column({ type: 'json' }) clothing_data: DrawableData[];
    @Column({ type: 'json' }) prop_data: DrawableData[];

    static async SaveAppearance(name: string, clothingData: DrawableData[], propData: DrawableData[], characterId = -1) {
        const res = await getRepository(this).save({ name, character_id: characterId, clothing_data: clothingData, prop_data: propData });
        return res;
    }
}
