import { DataTypes } from "sequelize";
import { sequelize } from "@/configs/sequelize";
import { User } from "./user";

export const Patient = sequelize.define(
    "Patient",
    {
        id: {
            type: DataTypes.UUID,
            primaryKey: true,
            defaultValue: DataTypes.UUIDV4,
        },
        fullname: {
            type: DataTypes.STRING,
            unique: true,
            allowNull: false,
        },
        gender: {
            type: DataTypes.ENUM("male", "female"),
            allowNull: false,
        },
        birth_date: {
            type: DataTypes.DATE,
            allowNull: false,
        },
        created_by_id: {
            type: DataTypes.UUID,
            allowNull: false,
        },
    },
    {
        tableName: "patients",
        timestamps: true,
        createdAt: "created_at",
        updatedAt: "updated_at",
    },
);

Patient.belongsTo(User, {
    foreignKey: "created_by_id",
    as: "created_by",
});
