const { empty } = require("../Helpers/Common");
const sequelize = require("../config/dbconnection");
const Sequelize = require('sequelize')



const getUnsignedDocumentsCount=async(partnerId)=>{
    let query=await sequelize.query(`select count(id) as count from partner_documents where partner_id=${partnerId} and file_name IS NULL and document_type=3`)
    if(query[0].length==1){
        return query[0][0];
    }
    else{
        return 0;
    }
}
const getNewrequestCount=async(partnerId=false)=>{
    let whereCondition = '';
    if(partnerId){
        whereCondition = ` rp.partner_id=${partnerId} and  `
    }
    let query=await sequelize.query(`select count(rp.id) as count from request_partners rp`
    +` left join requests r on r.id=rp.request_id`
    +` where ${whereCondition} rp.accept_status=1 and (r.status=2 OR (r.status=3 AND r.min_payment_status=0)) `)
    if(query[0].length==1){
        return query[0][0];
    }
    else{
        return 0;
    }
}
const getSkillById=async(table,field,id)=>{
    let query=await sequelize.query(`select service_id from ${table} where ${field}=${id} and status=1 order by id desc`)
    if(query[0].length>0){
        return query[0]
      }
      else{
        return false;
      }
}
module.exports={getUnsignedDocumentsCount,getNewrequestCount,getSkillById}