import { Column, Entity, JoinColumn, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { StateCodeChargeEntity } from './state-code-charge.entity';

export type CodeTitle = { id: number; name: string };

@Entity('state_codes')
export class StateCodeEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'varchar', length: 64 }) name: string;
    @Column({ type: 'varchar', length: 16 }) abbreviation: string;
    @Column({ type: 'longtext' }) titles: CodeTitle[];

    @OneToMany(() => StateCodeChargeEntity, (scc) => scc.code, { eager: true })
    @JoinColumn({ referencedColumnName: 'code_id' })
    charges: StateCodeChargeEntity[];
}
