const { DataTypes } = require("sequelize");
const sequelize = require("../db");

const LEAVE_TYPES = [
  "Annual Leave",
  "Sick Leave",
  "Emergency Leave",
  "Maternity/Paternity Leave",
  "Unpaid Leave",
  "Other",
];

const LeaveRequest = sequelize.define(
  "LeaveRequest",
  {
    UserId: {
      type: DataTypes.INTEGER,
      allowNull: false,
    },
    CompanyId: {
      type: DataTypes.INTEGER,
      allowNull: false,
    },
    ReviewedById: {
      type: DataTypes.INTEGER,
      allowNull: true,
    },
    type: {
      type: DataTypes.ENUM,
      values: LEAVE_TYPES,
      allowNull: false,
    },
    startDate: {
      type: DataTypes.DATEONLY,
      allowNull: false,
    },
    endDate: {
      type: DataTypes.DATEONLY,
      allowNull: false,
    },
    comment: {
      type: DataTypes.TEXT,
      allowNull: true,
    },
    status: {
      type: DataTypes.ENUM,
      values: ["pending", "approved", "rejected"],
      defaultValue: "pending",
    },
    reviewNote: {
      type: DataTypes.TEXT,
      allowNull: true,
    },
    reviewedAt: {
      type: DataTypes.DATE,
      allowNull: true,
    },
  },
  {
    tableName: "LeaveRequests",
    timestamps: true,
  },
);

module.exports = LeaveRequest;
module.exports.LEAVE_TYPES = LEAVE_TYPES;
