const system = require("../../../system");
const ServiceBase = require("../../sve.base");
class TrademarkcaseService extends ServiceBase {
  constructor() {
    super("rejreex", ServiceBase.getDaoName(TrademarkcaseService))
    this.agentDao = system.getObject("db.rejreex.agentDao")
    this.applicantDao = system.getObject('db.rejreex.applicantDao')
  }

  async createCase (params) {
    return this.db.transaction(async (t) => {
      await this.dao.create(params.case, t)
      await this.agentDao.create(params.agents, t)
      await this.applicantDao.create(params.applicant, t)
    })
  }

  async getCase (id) {
    let query = {
      where: {
        caseId: id
      },
      include: [{
        model: this.agentDao.model,
        raw: true
      }, {
        model: this.applicantDao.model,
        raw: true
      }]
    }
    let result = await this.dao.model.findOne(query)
    result.setDataValue('agents', result.agents[0])
    result.setDataValue('applicants', result.applicants[0])
    return result
  }

  async getCaseList (params) {
    params.pageInfo = params.pageInfo || { pageNo: 1, pageSize: 10 }
    return await this.dao.findAndCountAll(params)
    // return await this.dao.model.findAndCountAll(query)
  }
}
module.exports = TrademarkcaseService;
