import { Injectable } from '@nestjs/common';
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
import { TaxEntity } from '../../domain/entities/tax.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { TaxModel } from '../models/tax.model';
import {
  CONNECTION_NAME,
  STATUS,
} from 'src/core/strings/constants/base.constants';
import { Repository } from 'typeorm';

@Injectable()
export class TaxDataService extends BaseDataService<TaxEntity> {
  constructor(
    @InjectRepository(TaxModel, CONNECTION_NAME.DEFAULT)
    private repo: Repository<TaxModel>,
  ) {
    super(repo);
  }

  async taxKeyValue(): Promise<any> {
    const taxes = await this.getManyByOptions({
      where: {
        status: STATUS.ACTIVE,
      },
    });

    const keyVal = {};

    for (const tax of taxes) {
      const { name, value } = tax;
      keyVal[name] = value / 100;
    }

    return keyVal;
  }
}
