import { GeneralService } from '../share/generalservice.js'

export class ReportService {

  constructor() {
    this.generalService = new GeneralService()
  }

  async getReportController(database, acpTime, expTime) {
    // trnprjseq,
    const sql = `
      SELECT 
        trnprjnam,
        trnexpbdg,
        ${database}.translatebdg(trnbdgcod) AS trnbdgnam,
        trnbdgcod,
        ${database}.translatedtl('COMSTT', trncomstt) AS trncomsttnam,
        trncomstt,
        trnacpdtm
      FROM ${database}.trnmst
      WHERE trnacpdtm BETWEEN $1 AND $2;
    `;

    const params = [acpTime, expTime];
    const result = await this.generalService.executeQueryParam(database, sql, params);
    return result
  }

  async getCategoryColorMap(database) {
    const sql = `
        SELECT dtlcod, dtlnam, dtlmsc as dtlclr
        FROM ${database}.dtlmst
        WHERE dtltblcod IN ('ACTCAT_INC', 'ACTCAT_EXP')
    `;
    const params = [];
    const rows = await this.generalService.executeQueryParam(database, sql, params);

    const map = {};
    rows.forEach(r => {
      map[r.dtlnam] = r.dtlclr;
    });

    return map;
  }
}