import {TransactType} from "./index";

export interface PronounData {
    id: string
    default_marker: string
    name: string
    display_order: number
    use_plural: boolean
    subjective: string
    adjective: string
    possessive: string
    reflexive: string
    objective: string
}

export interface GenderMarkerData {
    emoji: string
    default_name: string
    display_order: number
}

export interface GenderTablesData {
    pronouns: PronounData[]
    markers: GenderMarkerData[]
}

export interface GenderTable {
    getPronounsAndMarkers(): Promise<GenderTablesData>
}

export class GenderTablesImpl implements GenderTable {
    private readonly _transact: TransactType

    constructor({transact}: { transact: TransactType }) {
        this._transact = transact
    }

    async getPronounsAndMarkers(): Promise<GenderTablesData> {
        const result: GenderTablesData = {
            pronouns: [],
            markers: [],
        }
        await this._transact({
            readonly: true,
            async transaction(query) {
                const pronouns = await query<{id: string, default_marker: string, name: string, display_order: number, use_plural: boolean, subjective: string, adjective: string, possessive: string, reflexive: string, objective: string}>(
                    `SELECT id, default_marker, name, display_order, use_plural, subjective, adjective, possessive, reflexive, objective FROM pronouns`
                )
                const markers = await query<{emoji: string, default_name: string, display_order: number}>(
                    `SELECT emoji, default_name, display_order FROM gender_markers`
                )
                result.pronouns = pronouns.rows
                result.markers = markers.rows
            }
        })
        return result
    }
}