import DatabaseProperty from "./Database/DatabaseProperty";
import BadDataException from "./Exception/BadDataException";
import { ObjectType } from "./JSON";
import Zod from "../Utils/Schema/Zod";
export default class Name extends DatabaseProperty {
    get title() {
        return this._title;
    }
    set title(v) {
        this._title = v;
    }
    get name() {
        return this._name;
    }
    set name(v) {
        this._name = v;
    }
    constructor(name) {
        super();
        this._title = "";
        this._name = "";
        this.name = name;
    }
    getFirstName() {
        return this.name.split(" ")[0] || "";
    }
    getLastName() {
        if (this.name.split(" ").length > 1) {
            return this.name.split(" ")[this.name.split(" ").length - 1] || "";
        }
        return "";
    }
    getMiddleName() {
        if (this.name.split(" ").length > 2) {
            return this.name.split(" ")[1] || "";
        }
        return "";
    }
    toString() {
        return this.name;
    }
    static toDatabase(value) {
        if (value) {
            if (typeof value === "string") {
                value = new Name(value);
            }
            return value.toString();
        }
        return null;
    }
    toJSON() {
        return {
            _type: ObjectType.Name,
            value: this.toString(),
        };
    }
    static fromJSON(json) {
        if (json["_type"] === ObjectType.Name) {
            return new Name(json["value"] || "");
        }
        throw new BadDataException("Invalid JSON: " + JSON.stringify(json));
    }
    static fromDatabase(_value) {
        if (_value) {
            return new Name(_value);
        }
        return null;
    }
    static getSchema() {
        return Zod.object({
            _type: Zod.literal(ObjectType.Name),
            value: Zod.string().openapi({
                type: "string",
                example: "John Doe",
            }),
        }).openapi({
            type: "object",
            description: "Name object",
            example: { _type: ObjectType.Name, value: "John Doe" },
        });
    }
}
//# sourceMappingURL=Name.js.map