const sequelize = require("../config/dbconnection");
const Sequelize = require("sequelize");
const Admin = require("../models/admin");
const { empty, getAgoString } = require("../Helpers/Common");

const TeamStages = sequelize.define('team_stages', {
  ID: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },
  team_id: { type: Sequelize.INTEGER, allowNull: false, defaultValue: null },
  workflow_id: { type: Sequelize.INTEGER, allowNull: false, defaultValue: null },
  stage_id: { type: Sequelize.INTEGER, allowNull: false,defaultValue:null },
  stage_type: { type: Sequelize.TINYINT, allowNull: false, defaultValue: null },
  position_order: { type: Sequelize.TINYINT, allowNull: false, defaultValue: null },
  stage_submit: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1 },
  added_by: { type: Sequelize.INTEGER, allowNull: false, defaultValue: null },
  timestamp: { type: Sequelize.INTEGER, allowNull: false, defaultValue: null },
  updated_on: { type: Sequelize.INTEGER, allowNull: false, defaultValue: null },
  approved_on: { type: Sequelize.INTEGER, allowNull: true, defaultValue: null },
  approved_by: { type: Sequelize.INTEGER, allowNull: true, defaultValue: null },
  status: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1 },
},{timestamps:false})



const addTeamStage = async(data)=>{
    try {
        let result = await TeamStages.create(data)
        return result.id
    } catch (error) {
        console.log(error)
    }
}
const updateTeamstage=async(id,data)=>{
    try {
        let result = await TeamStages.update(data,{
            where:{
                id:id
            },returning:true
        })
      return true
    } catch (error) {
        console.log(error)
    }
}

module.exports={
    addTeamStage,
    updateTeamstage,
}