"use strict";
const { Model, DataTypes } = require("sequelize");

module.exports = (sequelize) => {
  class Attedances extends Model {
    static associate(models) {
       this.belongsTo(models.User, {
        foreignKey: 'user_id',
        as: 'user'
       })
       this.belongsTo(models.Branch, {
        foreignKey: 'branch_id',
        as: 'branch',
        onDelete: 'CASCADE'
       })
    }
  }

  Attedances.init({
    id: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      allowNull: false,
      primaryKey: true,
    },
    user_id: {
        type: DataTypes.UUID,
        allowNull: false,
    },
    branch_id: {
        type: DataTypes.UUID,
        allowNull: false,
    },
    date: {
        type: DataTypes.DATEONLY,
        allowNull: false
    },
    lunch_in: {
      type: DataTypes.DATE,
      allowNull: true,
    },
    
    photo: {
       type: DataTypes.STRING,
       allowNull: true
    },
    clock_in: {
        type: DataTypes.DATE,
    },
    clock_out: {
        type: DataTypes.DATE
    },
    name: {
      type: DataTypes.STRING,
      allowNull: true
    },
    lat: {
      type: DataTypes.DECIMAL(20, 15),
      allowNull: true,
    },
    lng: {
        type: DataTypes.DECIMAL(20, 15),
        allowNull: true,
    },
    type: {
        type: DataTypes.ENUM('present', 'sick', 'permission'),
        defaultValue: 'present'
    },
    reason:{
       type: DataTypes.TEXT
    },

    created_at: {
      type: DataTypes.DATE,
    },
    updated_at: {
      type: DataTypes.DATE,
    },
    deleted_at: {
      type: DataTypes.DATE,
    },
  },
    {
      sequelize,
      modelName: "Attedances",
      tableName: "ref_attedances",
      timestamps: true,
      createdAt: "created_at",
      updatedAt: "updated_at",
      deletedAt: "deleted_at",
      paranoid: true,
    });

  return Attedances;
};
