const sequelize = require("../config/dbconnection")
const Sequelize = require('sequelize')

const requestUpdates = sequelize.define('request_updates', {
    id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },
    request_id:{type:Sequelize.INTEGER,allowNull:false},
    partner_id:{type:Sequelize.INTEGER,allowNull:true},
    partner_name:{type:Sequelize.STRING,allowNull:true,},
    activity:{type:Sequelize.STRING,allowNull:false,},
    added_by: {type:Sequelize.INTEGER,allowNull:false,},
     timestamp: {type:Sequelize.INTEGER,allowNull:false,},
     is_jobcost:{type:Sequelize.INTEGER,allowNull:false,defaultValue:0},
    status:{type:Sequelize.INTEGER,allowNull:false,defaultValue:1},
   
},{timestamps:false})

const DesignOrderUpdates = sequelize.define('design_order_updates', {
    id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },
    design_order_id	:{type:Sequelize.INTEGER,allowNull:false},
    partner_id:{type:Sequelize.INTEGER,allowNull:true},
    partner_name:{type:Sequelize.STRING,allowNull:true,},
    activity:{type:Sequelize.TEXT,allowNull:false,charset: 'utf8mb4',collate: 'utf8mb4_unicode_ci'},
    added_by: {type:Sequelize.INTEGER,allowNull:false,},
    timestamp: {type:Sequelize.INTEGER,allowNull:false,},
    status:{type:Sequelize.INTEGER,allowNull:false,defaultValue:1},
},{timestamps:false, tableName:'design_order_updates'})

const addRequestUpdate=async(data)=>{
    console.log('datayyyyyy', data)
    try {
        let results = await requestUpdates.create(data)
        if (results) {
            return true;
        }
        else {
            return false;
        }
    } catch (error) {
        console.log(error,'Error in adding request update ')
    }
}

const addDesignOrderUpdate=async(data)=>{
    try {
        let results = await DesignOrderUpdates.create(data)
        if (results) {
            return true;
        }
        else {
            return false;
        }
    } catch (error) {
        console.log(error,'Error in adding design order update ')
    }
}

module.exports={RequestUpdatesModel:requestUpdates, addRequestUpdate, addDesignOrderUpdate}