
const { empty } = require("../Helpers/Common");
const sequelize = require("../config/dbconnection");
const Sequelize = require('sequelize')
const onboardLink = sequelize.define('onboard_workflow_links', {
    id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },
    workflow_ids: { type: Sequelize.STRING, allowNull: false },
    partner_type_id: { type: Sequelize.INTEGER, allowNull: true, defaultValue: null },
    partner_id: { type: Sequelize.INTEGER, allowNull: true, defaultValue: null },
    token: { type: Sequelize.STRING, allowNull: false  },
    team_id: { type: Sequelize.STRING, allowNull: true, defaultValue: null },
    is_public: { type: Sequelize.INTEGER, allowNull: false ,defaultValue:0},
    timestamp: { type: Sequelize.INTEGER, allowNull: false },
    added_by: { type: Sequelize.INTEGER, allowNull: false },
   
    status: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1 },

}, { timestamps: false })



const isInviteLinkExist=async(token)=>{
    let query=await sequelize.query(`select l.token from onboard_workflow_links l where l.token="${token}" and l.status=1 `)
    if(query[0].length > 0){
        return true;
    }
    else{
        return false;
    }
}
const addInviteLink=async(data)=>{
    try {
        console.log("#########", data);
        let results = await onboardLink.create(data)
        console.log("#########", results);
        if (results) {
            return results;
        }
        else {
            return false;
        }
    }
    catch (error) {
        console.error("Error adding the Onboard Links ", error);
        return false;
    }
}

module.exports={addInviteLink,isInviteLinkExist}