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

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

  Branch.init({
    id: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      allowNull: false,
      primaryKey: true,
    },
    name: {
      type: DataTypes.STRING,
      allowNull: true
    },
    lat: {
      type: DataTypes.DECIMAL(20, 15),
      allowNull: false,
    },
    lng: {
        type: DataTypes.DECIMAL(20, 15),
        allowNull: false,
    },
    lunch_attendance: {
        type: DataTypes.BOOLEAN,
        defaultValue: false,
        allowNull: true
    },

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

  return Branch;
};
