import { Injectable } from '@nestjs/common';
import { SalesPriceFormulaEntity } from '../../domain/entities/sales-price-formula.entity';
import { InjectRepository } from '@nestjs/typeorm';
import {
  SalesPriceFormulaModel,
  TransactionSettingModel,
} from '../models/sales-price-formula.model';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { Repository } from 'typeorm';
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';

@Injectable()
export class SalesPriceFormulaReadService extends BaseReadService<SalesPriceFormulaEntity> {
  constructor(
    @InjectRepository(SalesPriceFormulaModel, CONNECTION_NAME.DEFAULT)
    private repo: Repository<SalesPriceFormulaModel>,

    @InjectRepository(TransactionSettingModel, CONNECTION_NAME.DEFAULT)
    private transactionSetting: Repository<TransactionSettingModel>,
  ) {
    super(repo);
  }

  async getTransactionSetting(): Promise<any> {
    try {
      const data = await this.transactionSetting.findOne({
        where: {},
        order: {
          created_at: 'DESC',
        },
      });

      return data;
    } catch (error) {
      throw error;
    }
  }
}
