import { z } from 'zod';

export default class Title  {
    prefix = `TITLE`
    indices = null

    constructor(indices) {
        this.indices = indices
    }

    schema = z.object({
        id: z.number(),
        name: z.string()
    })

    save(newTitle) {
        let id = `HY-${this.entries.length+1}`
        if(this.validate(id, newTitle)) {
            try {
                global.db.add(id, newTitle)
            } catch(e) {
                console.error(e)
                throw e
            }
        } else {
            throw new global.ServerError(400, "Invalid Member Data!");
        }
    }
}