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 { MchWithdrawChannelEntity } from '../entity/mchWithdrawChannel';

@Provide()
export class MchWithdrawChannelService extends BaseService {
  @InjectEntityModel(MchWithdrawChannelEntity)
  mchWithdrawChannelEntity: Repository<MchWithdrawChannelEntity>;

  
  async page(query) {
    let { mchId = '', currency = '', code = '', status = '' } = query;
    const sql = `SELECT * FROM dj_mch_withdraw_channel a WHERE 1=1
      ${this.setSql(mchId, 'and a.mchId like ?', [`%${mchId}%`])}
      ${this.setSql(currency, 'and a.code like ?', [`%${currency}%`])}
      ${this.setSql(code, 'and a.code like ?', [`%${code}%`])}
      ${this.setSql(status, 'and a.status like ?', [`%${status}%`])}
    `;
    return this.sqlRenderPage(sql, query);
  }


  async getByMchIdAndCurrency(mchId, currency) {
    return await this.mchWithdrawChannelEntity.findOneBy({
      mchId,
      currency,
      status: 1
    })
  }
}
