import Dexie, { type Table } from 'dexie';

export interface Badge {
    // id?: number;
    id_random: string;
    event_badge_id_random: string;
    event_id_random: string;
    full_name: string;
    full_name_override: null|string;
    email: string;
    email_override: null|string;
    affiliations: string;
    affiliations_override: null|string;
    badge_type: string;
    badge_type_code: string;
    badge_type_code_override: null|string;
    badge_type_override: null|string;
    external_event_id: string;
    external_id: string;
    external_person_id: string;
    created_on: Date;
    updated_on: Date;
}

export interface Exhibit {
    // id?: number;
    id_random: string;
    event_exhibit_id_random: string;
    event_id_random: string;
    code: string;
    name: string;
    tagline: null|string;
    description: null|string;
    staff_passcode: null
    data_json: null|string;
    leads_api_access: null|boolean;
    leads_custom_questions_json: null|string;
    leads_device_sm_qty: null|number;
    leads_device_lg_qty: null|number;
    license_max: number;
    license_li_json: null|string;
    cfg_json: string;
    enable: boolean;
    hide: boolean;
    priority: boolean
    sort: number;
    group: string;
    created_on: Date;
    updated_on: Date;
}

export class MySubClassedDexie extends Dexie {
    // 'badges' is added by dexie when declaring the stores()
    // We just tell the typing system this is the case
    badges!: Table<Badge>;
    exhibits!: Table<Exhibit>;

    constructor() {
        super('ae_events_db');
        this.version(1).stores({
          //   badges: '++id, full_name, email' // Primary key and indexed props
          badges: 'id_random, full_name, full_name_override, email, email_override, affiliations, affiliations_override, badge_type, badge_type_code, badge_type_code_override, badge_type_override, external_event_id, external_id, external_person_id, created_on, updated_on', // Primary key and indexed props
          exhibits: 'id_random, code, name, description, staff_passcode, data_json, license_max, license_li_json, cfg_json, created_on, updated_on',
          });
    }
}

export const db_events = new MySubClassedDexie();