import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { Gender } from '../../shared/const/gender.const';
import { CharacterEntity } from './character.entity';

export type CharacterOutfitStackPart = [number, number] | null;
export type CharacterOutfitStack = [
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
];

export type CharacterOutfitStackProps = [
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
    CharacterOutfitStackPart,
];

export type CharacterOutfitStackState = [
    boolean,
    boolean,
    boolean,
    boolean,
    boolean,
    boolean,
    boolean,
    boolean,
    boolean,
    boolean,
    boolean,
    boolean,
];

export enum CharacterOutfitOverrideLayer {
    FactionUniform,
    CompanyUniform,
    PrisonUniform,
}

export enum CharacterOutfitOverrideKey {
    FactionUniform = 'Faction Uniform',
    CompanyUniform = 'Company Uniform',
    PrisonUniform = 'Prison Uniform',
}

export interface CharacterOutfitOverride {
    components: CharacterOutfitStack;
    props?: CharacterOutfitStackProps;
    resumeOnReconnect?: number;
    key: CharacterOutfitOverrideKey;
    layer: CharacterOutfitOverrideLayer;
}

@Entity('character_outfits')
export class CharacterOutfitEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column() character_id: number;
    @Column({ type: 'int' }) character_gender: Gender;
    @Column({ type: 'varchar', length: 64 }) name: string;
    @Column({ type: 'json' }) components: CharacterOutfitStack;

    @ManyToOne(() => CharacterEntity, (character) => character.outfits)
    @JoinColumn({ name: 'character_id' })
    character: CharacterEntity;
}
