import { Provide } from '@midwayjs/decorator';
import { BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import * as _ from 'lodash';
import { WithdrawChannelEntity } from '../entity/withdrawChannel';

@Provide()
export class WithdrawChannelService extends BaseService {
  @InjectEntityModel(WithdrawChannelEntity)
  withdrawChannelEntity: Repository<WithdrawChannelEntity>;

  async queryByCurrency(currency) {
    return await this.withdrawChannelEntity.findBy({
      status: 1,
      currency,
    });
  }

  async queryByCode(code) {
    return await this.withdrawChannelEntity.findOneBy({
      status: 1,
      code,
    });
  }

  async getWithdrawChannelList() {
    return await this.withdrawChannelEntity.find({
      where: {
        status: 1
      },
      select: ['name', 'code', 'currency']
    })
  }
}
